javascript - 内置[[Call]]和[[Construct]]算法理解

标签 javascript ecmascript-6

9.3.1 [[Call]](thisArgument, argumentsList)

  1. 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)

  1. 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 of F

开始,这一行在 section 9.3.1section 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是实现定义的。步骤是

  1. Let P be ? ToPropertyKey(V).
  2. Let O be ? ToObject(this value).
  3. Return ? HasOwnProperty(O, P).

但是这些步骤如何在引擎中实际执行并不重要,只要它们发生即可。

关于javascript - 内置[[Call]]和[[Construct]]算法理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49622627/

相关文章:

javascript - ng-swipe-down 和 ng-swipe-up 不起作用

javascript - Object.Freeze Javascript

javascript - 在异步回调函数生成的错误上使用 try catch

javascript - 如何就地更新 JSON key ?

javascript - react : rendering components in a loop

Javascript 适用于 Chrome、Safari 和 Opera,但不适用于 Firefox

javascript - 如何在加载某些异步数据(在 Vuex 存储中)之前防止任何路由?

javascript - 使用 postmessage 发回消息

javascript - 设置请求 header jQuery Ajax

javascript - ES6 析构并获取值