Function.prototype.myBind = function(that) {
if (typeof this !== 'function') {
throw new Error('must be function');
}
const _self = this;
const args = Array.prototype.slice.call(arguments, 1);
return function() {
return _self.apply(that, [...args, ...arguments])
}
}
function add(num1, num2) {
return num1 * num2;
}
const res = add.myBind(this, 6);
const res1 = res(2);
console.log('res1', res1); // 12
函数柯里化---实现Function.prototype.bind
最新推荐文章于 2024-05-01 11:05:38 发布