Are synonyms "target" and "receive" in the ES2015 specification?

Both "receivers" and "targets" are used in the ES2015 specification (see examples below) and elsewhere on the Internet to refer to an object used as the value of this .

Are these words synonymous or have subtly different meanings?

Is there one correct term to refer to the value of this function during a call?

Note that the signature Reflect.get in 26.1.6 uses both terms indicating the difference in meaning.

This issue is related to the alleged inconsistency of nomenclature in the ES2015 specification.

Examples of using:

Table 5, line 7 ( [[Get]] ), section 6.1.7.2 (my courage):

Returns the value of the property whose key is the Key property of this object. If any ECMAScript code must be executed to retrieve the value of a property, the Recipient is used as that value when evaluating the code.

Paragraph 2, section 6.1.7.2 (my courage):

Internal method names are polymorphic. This means that different values ​​of an object can be performed by different algorithms when a common internal method name is called on them. This actual object, the internal method is called - this is the " target " call. I have a thick runtime, the implementation of the algorithm is trying to use the internal method of an object that the object does not support, an exception of type Error is fixed.

+6
source share
1 answer

Repeat:

  • Each call to an object’s internal method has a “target”, the object to which the call is made.

  • "Receiver" is a parameter of 2 nd of the [[Get]] method and 3 rd of the [[Set]] method.

  • Other internal object methods do not have this additional parameter.

Then why do [[Get]] and [[Set]] have a receiver? Because it is not a goal.

The receiver is used to call getter and setter in the [[Get]] / [[Set]] area.

ES6 9.1.8 :

  • You call A.Get( 'property', A )
  • If A does not have a property, A.prototype.Get( 'property', A ) called.
    1. The target is now "A.prototype". But the receiver remains "A".
    2. If A.prototype has a getter function for the property, it will be called with receiver A instead of the target A.prototype.

Note that ES5 [[Get]] (8.12.3) does the same thing differently and without a receiver, in part because the ascent prototype takes place in another part (8.12.2).

The receiver exists only in the context of [[Get]] and [[Set]] and serves a different purpose than the target.

  • When [[Get]] is necessary to indicate your goal, use O.
    O differs for each recursive call [[Get]] when it goes up the prototype chain.

  • The receiver remains the same as [[Get]] goes up the prototype chain. Its value is passed to getter as a parameter, and the following does not occur in the same area as the receiver.

O and Receiver can refer to the same object, but this does not matter in the context of [[Get]] or [[Set]]. In fact, Reflect.get allows the caller to set a different target and receiver and to distinguish them from the transition.

For other methods of internal objects, most of them do not go up the prototype chain at all. The two that do ( [[HasProperty]] and [[Enumerate]] ) do not need to keep the original target (so to speak).


With that in mind, you then ask if the Recipient specification gives a value that will be used in a general discussion of JavaScript, for example, how it defines a “target” in 6.1.7.2. This answer is no.

  • "Receiver" has a very narrow scope, which is used only as a parameter name, but "target" is used there in a general, less formal way.

  • "target" is a term borrowed from general discussion - ES5 does not define the concept of a call target. ES5 "target" may be a parameter, variable, expression, expression, or function called. But not an implied replacement for this .

  • The spectrum is written to convey "JavaScript behavior" in very, very precise terms, which makes it very technical, including the use of a parameter. It just serves for different communication than general discussions in programming.

    3.a. Many JS developers do not read the spec at all. This is not necessary for everyday encoding.

    3.b. We are talking about “closing”, “chaining areas”, “event queue” and “bold arrow” or “lambda”, right? The specification did not define any of these conditions.

    3.c. A specification may call things differently, for example, in the context of execution or in a job queue.
    It may just not name things. Closing is a new behavior.
    And when he calls the name, he does not create a pseudonym. The arrow function is never called a lambda.

The spectrum does not govern general discussions.
Use common sense for general discussions.

+9
source

All Articles