[英]How to remove a property added to a class instance with Object.defineProperty?
It seems I can't just delete it, check it: 看来我不能只删除它,请检查它:
class classy { constructor() { this.a = "I am classy"; } } var o = new classy(); Object.defineProperty(o, "b", {"get":()=>"hello"}); console.log("testing ob = " + ob); delete ob; console.log("deleted ob = " + ob);
The default value of configurable
is false
so you should set it to true
to be able to delete that property.. 可
configurable
的默认值为false
因此您应该将其设置为true
以能够删除该属性。
class classy { constructor() { this.a = "I am classy"; } } var o = new classy(); Object.defineProperty(o, "b", { "get": () => "hello", configurable: true }); delete ob; console.log(ob)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.