“delete”的返回值的真正含义是什么? [英] What is the true meaning of the returned value of `delete`?
问题描述
根据此MDN页面, delete
关键字
只有属性存在且不能删除时才返回false。
但是,我发现 delete 的情况, code>返回
true
,尽管该属性未被删除:
删除窗口
删除警报
删除目录
删除控制台
删除2
删除空白
删除{} .x
...
实际上,几乎所有 window
通过在 about:blank
中运行以下脚本可以看出
for(a in window){if(delete window [a]){console.log(a);然而,大多数属性 window
>
>实际上不会被删除。返回值 delete
的真正含义是什么?为什么它会返回 true
它没有删除的属性?
(注意:我会对参考文献感兴趣以解释 delete
的行为的Chromium代码。) 是一个主机对象,其语义由主机环境定义,例如浏览器。 delete
在应用于主机对象的属性时比应用于本机对象时要复杂。
$主机对象可以支持这些内部属性和任何依赖于实现的行为,只要它符合本文所述的特定主机对象限制。 b $ b
第11.4.1节 - 所以当一个主机对象不支持删除或修改一个属性时,它返回一个无法解析参考或假装被删除的参考。任何一种方法都会导致 According to this MDN page, the Returns false only if the property exists and cannot be deleted. It
returns true in all other cases. However, I see cases where In fact, almost all properties of However, most properties of (Note: I would be interested in references to Chromium code explaining the behaviour of The window is a host object, one whose semantics are defined by the host environment, e.g. the browser. Host objects may support these internal properties with any implementation-dependent behaviour as long as it is consistent with the specific host object restrictions stated in this document. Section 11.4.1 - The so when a host object doesn't support deletion or modification of a property, then it returns an unresolvable reference or a reference which pretends to be deleted. Either approach causes 这篇关于“delete”的返回值的真正含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!删除$ c $如果IsUnresolvableReference(ref)那么
如果IsStrictReference(ref)是真的,抛出一个SyntaxError异常。
否则,返回true。
true
以非严格模式返回。delete
keyword
delete
returns true
, despite the property not being deleted:delete Window
delete alert
delete dir
delete console
delete 2
delete null
delete {}.x
...
window
return true with delete
, as can be seen by the running the following script in about:blank
:for(a in window) { if(delete window[a]) { console.log(a); } }
window
do not actually get deleted. What is the true meaning of the returned value of delete
? Why does it return true
for properties it doesn't delete?delete
.)delete
when applied to properties of host objects is more complicated than when applied to native objects.
delete
operator saysIf IsUnresolvableReference(ref) then,
If IsStrictReference(ref) is true, throw a SyntaxError exception.
Else, return true.
true
to be returned in non-strict mode.