JavaScript/new.target:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第204行: 第204行:
typeof bar;
typeof bar;
bar.constructor;
bar.constructor;
Object.prototype.toString.call(bar);
typeof User;
typeof User;
User.constructor;
User.constructor;
Object.prototype.toString.call(User);
</syntaxhighlight>|{{consoleout|<pre>
</syntaxhighlight>|{{consoleout|<pre>
"object"
"object"
第212行: 第214行:
   console.log(this);
   console.log(this);
}
}
"[object Object]"
"function"
"function"
ƒ Function() { [native code] }
ƒ Function() { [native code] }
"[object Function]"
</pre>}}}}
</pre>}}}}
可以看到 bar 和 User 的本质区别一个是函数一个是函数对象。所以不能说 new 出来的构造函数不能使用 bind,而是生成的构造函数的 object 类型不能使用 bind。
=== 模拟实现 ===