if (!Function.prototype.bind) {
Function.prototype.bind = function () {
var self = this, // 保存原函数
context = [].shift.call(arguments), // 保存需要绑定的this上下文
args = [].slice.call(arguments); // 剩余的参数转为数组
return function () { // 返回一个新函数
self.apply(context,[].concat.call(args, [].slice.call(arguments)));
}
}
}https://www.cnblogs.com/liubingyjui/p/10799019.html
// 实现一个函数柯里化的原生bind方法
Function.prototype._bind = function (context) {
let self = this;
let firstArg = Array.prototype.slice.call(arguments,1);
return function () {
let secArg = Array.prototype.slice.call(arguments);
let finishArg = firstArg.concat(secArg);
return self.apply(context,finishArg);
}
}
京公网安备 11010502036488号