สำหรับสิ่งนี้ ให้ใช้คำสำคัญ “นี้”
ตัวอย่าง
ต่อไปนี้เป็นรหัส -
class Employee {
constructor() {
this.tempObject = [
{
firstName: "David",
setTheAnotherFirstName() {
this.firstName = "Carol";
},
},
];
}
}
var empObject = new Employee();
empObject.tempObject[0].setTheAnotherFirstName();
console.log("The Change First Name is=" + empObject.tempObject[0].firstName); ในการรันโปรแกรมข้างต้น คุณต้องใช้คำสั่งต่อไปนี้ -
node fileName.js.
ที่นี่ ชื่อไฟล์ของฉันคือ demo220.js
ผลลัพธ์
ผลลัพธ์จะเป็นดังนี้ −
PS C:\Users\Amit\JavaScript-code> node demo220.js The Change First Name is=Carol