[英]How to remove property from document?
I'm trying to manipulate document.oncopy
property for my tests.我正在尝试为我的测试操作
document.oncopy
属性。 And can't figure it out how to accomplish that.并且无法弄清楚如何做到这一点。 I've already tried the following approach.
我已经尝试过以下方法。
I wonder why it won't delete the property.我想知道为什么它不会删除该属性。
Object.defineProperty(document, 'oncopy', { configurable: true, get () {}, }); console.log('oncopy' in document);
delete document.oncopy; console.log('oncopy' in document);
'oncopy' in document
says true
. 'oncopy' in document
true
。
The method exists (as a getter/setter) on Document.prototype
.该方法存在于
Document.prototype
上(作为 getter/setter)。 If you want to completely remove it from the prototype chain so that the in
test results in false
, remove it from the prototype object:如果您想将其从原型链中完全删除,以便
in
测试结果为false
,请将其从原型对象中删除:
delete Document.prototype.oncopy console.log('oncopy' in document);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.