[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/new.target [Back]  [Original]

new.target - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

new.target

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2017 ..

new.target new. new, new.target . new.target undefined.

In this article

new.target

new.target new, , target. new , new . , new.target new new .

new.target . , new.target new.target .

new.target

( ), new.target undefined. new .

js
function Foo() {
  if (!new.target) throw "Foo() must be called with new";
  console.log("Foo instantiated with new");
}

new Foo(); //  "Foo instantiated with new"
Foo(); //  "Foo() must be called with new"

new.target

, new.target , new. , new.target , .

js
class A {
  constructor() {
    console.log(new.target.name);
  }
}

class B extends A {
  constructor() {
    super();
  }
}

var a = new A(); //  "A"
var b = new B(); //  "B"

Specification
ECMAScript 2027 LanguageSpecification
# sec-built-in-function-objects


Web Proxy Viewer  |  New URL  |  Original Page