任何人都知道谁将JS回调绑定到" bind()"?
根据三星规格:
2013在V8上:工作正常(请参阅链接的镜头,太大而无法添加)
2012是在松鼠上:获得异常:" bind()"作为功能不可用(请参阅链接射击,太大而无法添加)
)有问题的代码是:
var extJsCallBacks = [
function(){this._setupSystemInfo();}.bind(this),
function(){this._setupConfigInfo();}.bind(this),
function(){this._setupRepository();}.bind(this),
function(){this._setupContents();}.bind(this)
];
有任何提示?
在mdn上找到的polyfill
if (!Function.prototype.bind) {
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
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
if (this.prototype) {
// Function.prototype doesn't have a prototype property
fNOP.prototype = this.prototype;
}
fBound.prototype = new fNOP();
return fBound;
};
}