function aaa(){
if(!new.target){
console.log(111);
}else{
console.log(222);
console.log(new.target);
}
}
new aaa();//222
aaa();//111,ƒ aaa()
- ECMAScript中的函数始终可以作为构造函数实例化一个新对象,也可以作为普通函数被调用。
- 如果函数正常调用,则new.target的值是undefined;
如果是使用new关键字调用的,则new.target将引用被调用的构造函数。