感觉如果直接在bind里面就写call和apply,感觉考察重心偏离了,我个人重新写了一个,希望老师看一下。
Function.prototype.myBind = function(target){
var that = this;
var args = []
for(let i = 0 ; i < arguments.length ;i++){
args[i] = arguments[i];
}
args.length = arguments.length;
return function(){
target.fn = that;
let myArgs = [];
for(let i = 1; i < args.length ;i++){
myArgs.push("args["+i+"]");
}
eval("target.fn("+args.toString()+")");
delete target.fn;
}
}