【发布时间】:2017-08-23 08:39:58
【问题描述】:
谁能举例说明这个算法是如何工作的?
GetValue (V)#
1. ReturnIfAbrupt(V).
2. If Type(V) is not Reference, return V.
3. Let base be GetBase(V).
4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception.
5. If IsPropertyReference(V) is true, then
a. If HasPrimitiveBase(V) is true, then
i. Assert: In this case, base will never be null or undefined.
ii. Let base be ToObject(base).
b. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)).
6. Else base must be an Environment Record,
a. Return ? base.GetBindingValue(GetReferencedName(V), IsStrictReference(V)) (see 8.1.1).
http://www.ecma-international.org/ecma-262/7.0/#sec-getvalue
如果有人举例说明它是如何工作的,那就太好了。我试过了,但我不太明白。
举例说明:
let a = 10, b = {name: "Unknown"};
(null, a);
(null, a.name);
(null, b);
(null, b.name);
(null, b.surname);
(null, 10);
/// etc...
【问题讨论】:
-
这看起来像伪代码,你必须实现这个吗?提供你做了什么...
-
@Hitmands 为了让你理解我,我想通过一个真实的例子来了解它是如何工作的。例如,我们将添加
("" + Object.prototype)。此外,还有一个算法,它为每个操作数调用 GetValue(V),我想考虑算法中所有可能情况的分支 (GetValue())。 -
你是什么意思,“这是如何工作的”?这就是算法是的内容,是对某事物如何工作的描述。您尝试了什么但无法理解?
-
@Bergi,methinks,作者想要示例,如何将此算法应用于具体代码,例如块中的代码解释示例。例如,如果只写变量名或变量属性等,将选择哪些分支。
-
@Grundy 他应该表现出一些努力,然后发布他认为算法如何在这些示例上执行的内容。或者更具体地询问他尝试和失败的过程的某些部分。