What is `base value` of `reference` in ECMAScript(ECMA-262 5.1)?

无人久伴 提交于 2019-12-09 05:33:05

问题


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 flagto 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

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