How does the
- Step 1: create a new object by
- Step 2: call
MyClass's constructor function (the MyClass itself if and only if (iff) it is a function) with
thisset as the object created in step 1.
- Step 3: if the constructor returns an object, used this object as the returned value for the
newoperator. Otherwise, the object created in step 1 is returned.
All these expressions are equivalent:
new Object// not recommended as it would produce an unintended result such as with something like
new.target expression is available in a constructor function's body (class's constructor or the function).
Its value is evaluated as the operand class/function of the
new operator which initiates the constructor, or
undefined if the function is invoked as a normal function call (i.e., without the
This is useful when you want to identify the descendant class from the ancestor's constructor, or when you want to specify whether the function is invoked with/without the