(JS)手写bind函数
Function.prototype.binds = function() {
// 将参数解析为数组
const args = Array.prototype.slice.call(arguments);
// 取出数组第一项,其余的为参数(同时获取this)
const t = args.shift();
const self = this;
return function() {
return self.apply(t,args)
}
}
(JS)手写bind函数
Function.prototype.binds = function() {
// 将参数解析为数组
const args = Array.prototype.slice.call(arguments);
// 取出数组第一项,其余的为参数(同时获取this)
const t = args.shift();
const self = this;
return function() {
return self.apply(t,args)
}
}