您可以使用bind
的填充,如MDN's one。正如链接中指出的那样,它与本地网站有一些不同之处。
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;
};
}
见http://lesscss.org/usage/#browser-support,即:“如果你需要在一个较旧的浏览器上运行更少,请使用[ES-5垫片] (https://github.com/kriskowal/es5-shim),它将添加不太需要的javascript功能。“ –
谢谢。会看看。 –