什麼是 JavaScript 中的“new”運算子?
在 JavaScript 中,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>
廣告