简体   繁体   English

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

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

> delete document
  false

This I kind of understand: document is a non-configurable property of window. 我有点理解:文档是window的不可配置属性。

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

But what witchcraft is this? 但是,这是什么巫术?

Because document doesn't have a "body" property. 因为文档没有“ body”属性。 Or rather it doesn't have its OWN property. 或者更确切地说,它没有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.

相关问题 我无法将 PreactX 组件直接渲染到 document.body 中 - I can't render PreactX component directly into document.body 为什么不能使用MutationObserver API在document.body上观察document.write? - Why can't observe document.write on document.body using MutationObserver API? 为什么我需要使用Mootools Element方法扩展document.body $(document.body)? - Why do I need to do $(document.body) to extend document.body with Mootools Element methods? 为什么不能像document.body一样通过标记名称选择元素对象? - Why can't element objects be selected by tag name just like document.body? 为什么$(window [&#39;iframeName&#39;]。document.body).html()在我更改.attr(&#39;src&#39;)时不起作用 - why $(window['iframeName'].document.body).html() doesn't work when i change .attr('src') 为什么在“冻结” document.body对象之后,可以修改其属性? - Why after “freezing” the document.body object, I can modify its properties? 为什么我的javascript中的document.body为null? - Why is document.body null in my javascript? Javascript onload无法正常工作(“未捕获的TypeError:无法将属性&#39;document.body&#39;设置为null”) - Javascript onload isn't working (“Uncaught TypeError: Cannot set property 'document.body' of null ”) document.Body ComponentQuery - document.Body ComponentQuery document.body为null - document.body is null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM