What is a direct reference?

巧了我就是萌 提交于 2019-12-22 04:56:35

问题


One of the strict mode rules (Annex C) states:

When a delete operator occurs within strict mode code, a SyntaxError is thrown if its UnaryExpression is a direct reference to a variable, function argument, or function name.

So in this code:

delete x

x is a reference. (I know this because "the result of evaluating an Identifier is always a value of type Reference"). But is it a direct reference?

And, are there other kinds of references? Indirect references? (If not, what's the point of using the word "direct" at all?)


回答1:


Yes, there are different kinds of References (EcmaScript §8.7). The member operators (EcmaScript §11.2.1) for example do result in references whose base value is the value of the baseReference, which I'd call "not direct". A "direct reference" would be an identifier reference (EcmaScript §10.2.2.1, where the base value is an Environment Record.




回答2:


Anything that's not defined as a property if I understand it correctly.

These should throw errors or fail in a console:

(function(){ 'use strict'; var x = '2'; delete x; })();
(function(){ 'use strict'; delete arguments[0]; })('2');


来源:https://stackoverflow.com/questions/12610265/what-is-a-direct-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!