pseudo-property lets you detect whether a function or constructor was called using the new operator. In constructors and functions invoked using the new operator, returns a reference to the constructor or function. In normal function calls, is undefined .


描述 syntax consists of the keyword new , a dot, and the identifier target . Normally, the left-hand side of the dot is the object on which property access is performed, but here, new is not an object. pseudo-property is available in all functions.

In class constructors, it refers to the constructed class.

In ordinary functions, it refers to the function itself, assuming it was invoked via the new operator; otherwise is undefined .

In 箭头函数 , is inherited from the surrounding scope.

范例 in function calls

In normal function calls (as opposed to constructor function calls), is undefined . This lets you detect whether a function was called with new as a constructor.

function Foo() {
  if (! { throw 'Foo() must be called with new' }
  console.log('Foo instantiated with new')
new Foo()  // logs "Foo instantiated with new"
Foo()      // throws "Foo() must be called with new" in constructors

In class constructors, 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.

class A {
  constructor() {
class B extends A { constructor() { super() } }
let a = new A()  // logs "A"
let b = new B()  // logs "B"
class C { constructor() { console.log(  } }
class D extends C { constructor() { super()  } }
let c = new C()  // logs class C{constructor(){console.log(;}}
let d = new D()  // logs class D extends C{constructor(){super();}}

Thus from the above example of class C and D , it seems that points to the class definition of class which is initialized. For example, when d was initialized using new D() , the class definition of D was printed; and similarly, in case of c , the class C was printed.


ECMAScript (ECMA-262)
The definition of 'Built-in Function Objects' in that specification.


更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js Chrome 46 Edge 13 Firefox 41 IE 不支持 No Opera 33 Safari 11 WebView Android 46 Chrome Android 46 Firefox Android 41 Opera Android 33 Safari iOS 11 Samsung Internet Android 5.0 nodejs 5.0.0