问题
I've been trying to understand how this
value is set in javascript, and found ECMAScript Language Specification pretty much helpful. I was reading section 8.7 reference specification type
and found that reference in ECMAScript is made of 3 component, base value
, referenced name
, strict reference flag
to understand section 11.2.3.
I can assume what are referenced name
and strict reference flag
from their name, but i don't understand what is the base value
. The document says that base value
is either undefined
, String
, Boolean
, Number
and Object
, but it does not say how it is set and what it is. I am guessing it is something similar to context object. Could anyone explain?
回答1:
Yes, the base value is the context in which the referenced name lives.
For an object property, this would be the object (see §8.12 Object internal methods for setter/getter operations). For a variable, this would be the variable environment (§10.2.1 Environment records). For an unresolvable reference (the things that throw reference errors except when supplied to typeof), this would be undefined
.
it does not say how it is set
Reference
values are only constructed by very few operations:
- identifier reference expressions, that resolve the identifier in the current lexical environment (or one of its parents)
- property accessor expressions, i.e. the
.…
and[…]
operators - function calls to host functions are permitted to return them, but such don't exist.
来源:https://stackoverflow.com/questions/29353177/what-is-base-value-of-reference-in-ecmascriptecma-262-5-1