我一直在尝试理解 this
值是如何在 javascript 中设置的,并且发现 ECMAScript 语言规范非常有用。我在读section 8.7 reference specification type
发现ECMAScript中的引用由3个部分组成,base value
, referenced name
, strict reference flag
了解section 11.2.3 .
我可以根据他们的名字假设什么是referenced name
和strict reference flag
,但我不明白什么是base value
.文件说 base value
是 undefined
, String
, Boolean
, Number
和 Object
,但它没有说明它是如何设置的以及它是什么。我猜它类似于上下文对象。谁能解释一下?
最佳答案
是的,基值 是引用名称所在的上下文。
对于对象属性,这将是对象(有关 setter/getter 操作,请参阅 §8.12 Object internal methods)。对于变量,这将是变量环境 ( §10.2.1 Environment records )。对于不可解析的引用(抛出引用错误 except when supplied to typeof
的东西),这将是 undefined
。
it does not say how it is set
引用
值仅由极少数操作构成:
- identifier reference expressions , 那resolve the identifier在current lexical environment (或其 parent 之一)
- property accessor expressions ,即
.…
和[…]
运算符 - 允许对宿主函数的函数调用返回它们,but such don't exist .
关于javascript - ECMAScript(ECMA-262 5.1)中的 `base value` 的 `reference` 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29353177/