为什么不起作用?当我尝试调用 example.example() 时,我收到 TypeError: example.example is not a function.
var example = class {
constructor(){
this.example = false;
}
id(){
this.example = !this.example;
return this.example;
}
};
最佳答案
When I'm trying to call example.example() I'm getting TypeError: example.example is not a function.
example
是对匿名类的引用,它的构造函数只能用new
调用
您需要将其称为
var a = new example();
a.example; //false
演示
var example = class {
constructor() {
this.example = false;
}
id() {
this.example = !this.example;
return this.example;
}
};
var a = new example()
console.log(a.example);
关于javascript - 面向对象的JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48126328/