@panhonhang
2019-12-13T20:57:24.000000Z
字数 444
阅读 497
手撕代码
Function.prototype.bind1 = function(context){
let fn = this;
let arg = [...arguments];
arg.shift();
return function(){
return fn.apply(context,arg)
}
}
let a = function(name){
console.log(this.value);
console.log(name);
}
let b = {
value: 1,
}
let c = {
value: 3
}
let a2 = a.bind1(b,'aa')();
实现apply函数
Function.prototype.apply1 = function(context){
context.fn = this;
let list = [...arguments];
list.shift();
let result = context.fn(...list[0]);
delete context.fn;
return result;
}