JavaScript中的new关键字是new运算符,该运算符创建用户定义的对象类型的实例。
您可以尝试运行以下代码以使用new运算符创建JavaScript对象-
<!DOCTYPE html> <html> <body> <p id = "test"></p> <script> var dept = new Object(); dept.employee = "Amit"; dept.department = "Technical"; dept.technology ="Java"; document.getElementById("test").innerHTML = dept.employee + " is working on " + dept.technology + " technology."; </script> </body> </html>
输出结果
Amit is working on Java technology.