JavaScript中的删除运算符 [英] the delete operator in javascript
问题描述
我想问有关Java语言中删除"运算符的问题
I would like to ask questions about 'delete' operator in Javascript
为什么
delete window.document; // returns false
但是
delete navigator.geolocation; // returns true
我尝试了 navigator
的其他属性,但它仍然返回 true
I try other properties of navigator
and it still returns true
我已经检查了Webkit中的IDL, document
和 navigator
均为只读,
而且他们没有DontDelete属性但是为什么我可以删除一个而不删除另一个??
I have checked the IDL in webkit,
document
and navigator
are both of readonly,
and they dont have DontDelete attribute
but why I can delete one but not for the other???
推荐答案
If you'd like to understand the delete
operator, wrap your mind around the javascript spec section 11.4.1
在许多情况下,操作员应评估为 true
而不改变任何对象.
There are several cases where the operator should evaluate to true
without mutating any objects.
从8.12.7开始,操作员检查检查属性描述符的内部 [[Configurable]]
属性以强制执行只读属性.
From 8.12.7, the operator checks checks an internal [[Configurable]]
property of the property descriptor to enforce readonly properties.
这篇关于JavaScript中的删除运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!