class a {
get b() {
delete this.b;
return this.b = 1;
}
}
var c = {
get b() {
delete this.b;
return this.b = 1;
}
}
console.log(c.b); // works as expected
console.log((new a()).b); // throws error
Run Code Online (Sandbox Code Playgroud)
上面的代码应该工作正常,但最后一行抛出.
未捕获的TypeError:无法设置只有getter(...)的#的属性b
很明显,getter在类中没有被删除,而它在对象中工作正常.我是最新的稳定镀铬.