【发布时间】:2019-12-25 09:54:40
【问题描述】:
我尝试在我的类 Test 中使用 setter 方法,但我的日志返回“TypeError: testObject.id is not a function”
class test {
constructor() {
this._id = 0;
}
get id(){
return this._id;
}
set id(newId){
this._id = newId;
}
}
const testObject = new test();
console.log(testObject.id); // return 0
testObject.id(12); //return TypeError: myTest.id is not a function
console.log(testObject.id);
我希望输出为 12,但我得到了 TypeError。
【问题讨论】:
标签: javascript node.js class