9.3.1 [[Call]](thisArgument, argumentsList)
- Let result be the Completion Record that is the result of evaluating F in an implementation-defined manner that conforms to the specification of F. thisArgument is the this value, argumentsList provides the named parameters, and the NewTarget value is undefined.
9.3.2 [[Construct]](argumentsList, newTarget)
- Let result be the Completion Record that is the result of evaluating F in an implementation-defined manner that conforms to the specification of F. The this value is uninitialized, argumentsList provides the named parameters, and newTarget provides the NewTarget value.
您能向我解释一下这些建议的含义吗?我知道完成记录
是什么。如何理解这部分句子:以符合F规范的实现定义方式评估F的结果
最佳答案
result of evaluating
F
in an implementation-defined manner that conforms to the specification ofF
开始,这一行在 section 9.3.1和 section 9.3.2 。重要的是要考虑这里的上下文。如果你看the summary of section 9.3
The built-in function objects defined in this specification may be implemented as either ECMAScript function objects (9.2) whose behaviour is provided using ECMAScript code or as implementation provided function exotic objects whose behaviour is provided in some other manner. In either case, the effect of calling such functions must conform to their specifications.
这是关键部分。当您引用的行说“实现定义”时,它指的是这里。
例如,函数可以用 C++ 或 JS 引擎执行的任何其他语言来实现。所需要的只是该函数执行规范指定的操作。然而,它不必在 JS 本身中实现。
If the specification describes this, then where is the description of the evaluation?
由于本节是关于“内置函数”的,因此这里的行为是规范为 JS 函数定义行为的任何地方。例如,如果我们查看 section 17它指出:
Unless otherwise specified, each built-in function defined in this specification is created as if by calling the CreateBuiltinFunction abstract operation (9.3.3).
因此规范中定义的任何函数都具有这种实现定义的行为。例如Object.prototype.hasOwnProperty
是实现定义的。步骤是
- Let P be ? ToPropertyKey(V).
- Let O be ? ToObject(this value).
- Return ? HasOwnProperty(O, P).
但是这些步骤如何在引擎中实际执行并不重要,只要它们发生即可。
关于javascript - 内置[[Call]]和[[Construct]]算法理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49622627/