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