JavaScript中的new关键字是new运算符。它创建用户定义的对象类型的实例。
这是语法-
new constructor[([arguments])]
让我们看一个例子来学习new操作符的用法-
<!DOCTYPE html> <html> <body> <p id="test"> </p> <script> var dept = newObject(); dept.employee = "David"; dept.department = "Programming"; dept.technology = "C++"; document.getElementById("test").innerHTML = dept.employee + "is working on " + dept.technology + " technology."; </script> </body> </html>