> delete document
false
这个我有点理解:document是window的一个不可配置的属性。
> delete document.body
true
> document.body
<body>
...</body>
但这是什么巫术?
最佳答案
因为文档没有“正文”属性。或者更确切地说,它没有自己的属性(property)。
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)
关于javascript - 为什么我不能删除 document.body 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33293845/