What is the difference between `newTarget` and `F` in abstract operation `Construct(..)` ?

# Coolwust (10 years ago)

From ES 6, section 7.3.14, there is an abstract operation Construct (F, [argumentsList], [newTarget]), so if I have the following code var foo = new bar(), then newTarget is the same as F, which is bar.

My question is, in what situation, F is NOT the same as newTarget? And what is newTarget really?

# Axel Rauschmayer (10 years ago)

They diverge if a constructor makes a super-constructor call: The last constructor in a chain of super-constructor calls allocates the instance and it has to use newTarget.prototype as the prototype. newTarget is first filled in by the new operator and later passed on by super.

This is roughly similar to making super-method calls where this has to remain the same, because the super-method has to access the same instance properties.

# Allen Wirfs-Brock (10 years ago)

On Mar 16, 2015, at 10:32 AM, Coolwust wrote:

From ES 6, section 7.3.14, there is an abstract operation Construct (F, [argumentsList], [newTarget]), so if I have the following code var foo = new bar(), then newTarget is the same as F, which is bar.

My question is, in what situation, F is NOT the same as newTarget? And what is newTarget really?

super() calls within constructors

see people.mozilla.org/~jorendorff/es6-draft.html#sec-super-keyword-runtime-semantics-evaluation 3rd algorithm

# Coolwust (10 years ago)

Thanks very much for the explanation! it's clear now.