函数 | new.target属性 Posted on 2022-07-09 In JavaScript , 小众知识点 Symbols count in article: 414 Reading time ≈ 1 mins. new.target属性是ES6中新增的函数属性,new.target用于检测函数是否使用new关键字调用 如果函数是正常调用的,new.target的值为undefined;如果是使用new关键字调用的,则new.target将引用被调用的构造函数 123456789function King() { if (!new.target) { throw 'King must be instantiated unsing "new"!'; } console.log('King instantiated unsing "new"!')}new King(); // King instantiated unsing "new"!King(); // Error: King instantiated unsing "new"!