What is the difference between `newTarget` and `F` in abstract operation `Construct(..)` ?
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.
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 codevar foo = new bar()
, thennewTarget
is the same asF
, which isbar
.My question is, in what situation,
F
is NOT the same asnewTarget
? And what isnewTarget
really?
super() calls within constructors
see people.mozilla.org/~jorendorff/es6-draft.html#sec-super-keyword-runtime-semantics-evaluation 3rd algorithm
Thanks very much for the explanation! it's clear now.
My question is, in what situation,
F
is NOT the same asnewTarget
? And what isnewTarget
really?