IE下使用bind的JS方法
2015-03-26 13:40
239 查看
在写其它的JS代码前,先加入该段代码。
*该方法不知道来自哪里了,记录一下。
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 && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
*该方法不知道来自哪里了,记录一下。
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 && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
相关文章推荐
- AC_FL_RunContent.js的使用(IE中的Flash出现激活框的解决方法)
- js apply/call/caller/callee/bind使用方法与区别分析
- js apply/call/caller/callee/bind使用方法与区别分析
- js中call,apply和bind方法的区别和使用场景
- js中bind、call、apply的方法使用
- [转]IE下使用excanvas.js之后,动态创建的canvas不支持getContext的解决方法
- IE 无法使用 js trim() 的解决方法
- js apply/call/caller/callee/bind使用方法与区别分析
- IE下使用excanvas.js之后动态创建的canvas不支持getContext的解决方法(转)
- 分享一个js中的bind方法使用
- js apply/call/caller/callee/bind使用方法与区别分析
- IE 无法使用 js trim() 的解决方法
- js apply/call/caller/callee/bind使用方法与区别分析
- js apply/call/caller/callee/bind使用方法与区别分析
- js apply/call/caller/callee/bind使用方法与区别分析
- ie的js调试工具companion.js使用方法
- 【转】IE 无法使用 js trim() 的解决方法
- IE下使用js清空file控件值的几种方法
- 常用JS调试工具使用方法,帮你快速定位问题(Firebug+ IE“开发人员工具”)
- js apply/call/caller/callee/bind使用方法与区别分析