【new.target】
The new.target
property lets you detect whether a function or constructor was called using the newoperator. In constructors and functions instantiated with the new operator, new.target
returns a reference to the constructor or function. In normal function calls, new.target
is undefined
.
new.target
refers the constructor invoked by new
.
In class constructors, new.target
refers to the constructor that was directly invoked by new
. This is also the case if the constructor is in a parent class and was delegated from a child constructor.
参考:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target