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?)
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.
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