我担心的是,为什么严格地说,在<代码>delete上使用无保留识别码时,会发生yn误。
在多数情况下,如果你以通常的方式宣布与<代码>var关键词的变数,然后试图以无限制的方式使用<代码>delete,这种变数将无谓地失败,那么,严格方式避免在这些情况下出现错误。
However, there are cases where you can t delete identifiers that are qualified:
(function() {
// "use strict";
var obj = Object.create({}, { bloop: { configurable: false } });
delete obj.bloop; // throws TypeError in strict mode, silently fails in non-strict.
console.log( bloop in obj); // true
}());
严格控制方式必须在这里进行时间检查,因为遇到这种情况时,就会扔下一种类型。 在某些情况下,你can成功删除了非限制性方式中的无保留识别符号......
// "use strict";
window.bar = 6;
console.log(typeof bar); // number
delete bar; // works in non-strict, syntax error in strict!
console.log(typeof bar); // undefined
In fact, to my understanding, whether or not you can delete things (in non-strict mode) depends on the internal [[Configurable]]
property, and has nothing to do with qualified identifiers. As far as I can tell, there is no way in strict mode to delete non-global variables that (as properties of the local VO) are configurable:
(function() {
// "use strict";
eval( var foo = 5; );
console.log(typeof foo); // number
delete foo; // works in non-strict, SyntaxError in strict.
console.log(typeof foo); // undefined
}());
因此,我的问题是,在使用<代码>delete<>/code>时,如果财产不可以证明,那么类型Error会扔下任何东西,那么在使用“<代码>delete<>/code>时,究竟是怎样? 这似乎是一种不必要的限制,在某些情况下,除了不采用严格方式外,似乎还没有任何工作(第三例)。 谁能解释这一决定背后的动力?
最新情况:我刚刚认识到,我忽略了以下事实:直接的<代码>eval。 电话具有严格的范围,而不是电话功能的范围,例如第3条:<代码>foo 定义不严格。 无论如何,操作时间检查仍会达到这一目的,但它提出了一个附带问题: 我们没有办法严格地具有可塑性的地方变数:<代码>eval。 d 非限制性的变式声明? AFAIK是<代码>eval少数合法用途之一。