Reputation: 27425
Let we have a simple script:
obj=new String('str');//1
obj.length;//2
At line 1 we have a simple assignment which evaluated as follows:
obj
in my case). (undefined, obj, false)
will be returned as result.new String('str');
. Denote result of evalution by rref
GetValue(rref)
At this line obj-->'str'
bindings doesnt add to environment record of any execution contex. But when obj
PrimaryExpression:Identifier
will be evaluated as ('str', obj, false)
type Refernce and we can get property of 'str'
by this reference.
Question:
Why PrimaryExpression:Identifier
obj
at line 2 will be evaluated as ('str', obj, false)
?
Upvotes: 0
Views: 39
Reputation: 12477
This is an unusual sort of question for SO, but interesting nonetheless.
The answer to your question is that it gets added to the global execution context (assuming this script is the whole program).
See the ecma spec section regarding Programs.
Step 3 sets up an execution context for global code, and it's this context in which obj
is initially referenced, and which the PutValue
operation sets the binding of in your step 4 above.
Upvotes: 1