根据
this MDN page,删除关键字
@H_502_3@Returns false only if the property exists and cannot be deleted. It@H_502_3@但是,尽管没有删除该属性,我仍然看到delete的值为true的情况:
returns true in all other cases.
delete Window delete alert delete dir delete console delete 2 delete null delete {}.x ...@H_502_3@其实几乎所有属性的窗口都返回true,删除,可以看出运行下面的脚本关于:blank:
for(a in window) { if(delete window[a]) { console.log(a); } }@H_502_3@但是,窗口的大多数属性实际上并没有被删除.删除的返回值的真正含义是什么?为什么它不会删除的属性返回true? @H_502_3@(注意:我将有兴趣参考Chromium代码解释删除的行为.)
解决方法
该窗口是
host object,其语义由主机环境定义,例如浏览器.当应用于主机对象的属性时,删除比应用于本机对象时更复杂.
@H_502_3@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.@H_502_3@Section 11.4.1 – The
delete
operator说
If IsUnresolvableReference(ref) then,If IsStrictReference(ref) is true,throw a SyntaxError exception. Else,return true.@H_502_3@所以当一个主机对象不支持删除或修改一个属性时,它返回一个不可解析的引用或一个假装被删除的引用.任何一种方法都将以非严格模式返回true.