繁体   English   中英

为什么我不能删除document.body属性?

[英]Why can't I delete the document.body property?

> delete document
  false

我有点理解:文档是window的不可配置属性。

> delete document.body
  true
> document.body
  <body>
  ...</body>

但是,这是什么巫术?

因为文档没有“ body”属性。 或者更确切地说,它没有OWN属性。

 console.log(document.hasOwnProperty("body")); //false //now let's mimic what we're seeing with document.body function X(){ } X.prototype.body = "Abc"; var foo = new X(); console.log(foo.body); //Abc delete foo.body; //no effect because I don't have this property. My prototype does console.log(foo.body); //Abc (still) delete foo.__proto__.body; //delete the prototype's property console.log(foo.body); //undefined (now) delete document.__proto__.__proto__.body; //delete the doc console.log(document.body); //undefined (now) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM