簡體   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