이를 위해 "this" 키워드를 사용하십시오.
예시
다음은 코드입니다 -
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