New Operator
ใช้สร้าง Instance ของ Object ตามด้วย Constructor Method เช่น Object(), Array(), Date() (Built-in Functions)
var department = new Object();
var books = new Array("C++", "Perl", "Java");
var day = new Date("December 1, 2017");
Object() Constructor
Constructor คือฟังก์ชันสร้างและเริ่มต้น Object JavaScript มี Object() พิเศษสำหรับสร้าง Object ค่าที่คืนมาจะถูก Assign ให้ Variable Variable จะเก็บ Reference ไปยัง Object ใหม่ Property ไม่ใช่ Variable ไม่ต้องใช้ var
ตัวอย่าง
<html>
<head>
<title>Object Constructor</title>
<script>
var book = new Object();
book.subject = "Perl";
book.author = "Tutorialspoint";
</script>
</head>
<body>
<script>
document.write("Book name is : " + book.subject + "<br>");
document.write("Book author is : " + book.author + "<br>");
</script>
</body>
</html>
ผลลัพธ์
Book name is : Perl Book author is : Tutorialspoint