Function.prototype.handWrittenCall = function(){
let thisArg = arguments[0]?Object(arguments[0]): window;
thisArg.fn = this;
const args = Array.from(arguments).slice(1);
console.log('args',args);
const result = thisArg.fn(...args);
delete thisArg.fn;
return result;
}
obj = {
name:'张三',
fn:function(){
console.log('1',Array.from(arguments));
}
}
obj1={
name:'李四'
}
obj.fn.handWrittenCall(obj1,1,2,3)
手写简易call方法
最新推荐文章于 2024-11-02 12:42:04 发布