Javascript MDN函数#bind中出错?
只要看一下位于的“Polyfill”部分,我就注意到一些我认为可能是打字错误或代表我的错误:Javascript MDN函数#bind中出错?,javascript,Javascript,只要看一下位于的“Polyfill”部分,我就注意到一些我认为可能是打字错误或代表我的错误: Function.prototype.bind = function (oThis) { if (typeof this !== "function") { // closest thing possible to the ECMAScript 5 internal IsCallable function throw new TypeError("Function.pro
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
关于绑定函数(在绑定函数中称为fBound),apply语句涵盖了绑定函数可能被实例化的情况。然而,它进行的检查是,还提供了#bind的oThis参数。。。。如果是,它会忽略它,选择引用此。。。当然,所需要的只是fNOP的实例,而不需要&&oth这个布尔检查
return fToBind.apply(this instanceof fNOP ? this : oThis
毕竟,如果没有oThis,那么绑定函数就不能实例化,这不是ES5规则。还有其他人对它们的实现刮目相看吗?还是我的错?干杯 鲜为人知的事实是,MDN实际上是一个wiki,因此如果您不同意,可以建议对文档进行编辑。感谢adeneo,这一点很好,但我知道-我想接触的不仅仅是MDN社区(不要冒犯Moz)