JavaScript 中的"new"运算符是什么?
javascriptweb developmentfront end technology
JavaScript 中的 new 关键字是 new 运算符。它创建用户定义对象类型的实例。
语法
以下是语法 −
new 构造函数[([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>