UNPKG

npmrmftool1

Version:

rmf

15 lines 524 B
export function call(fn,obj,...args){ //this(...args)//执行了函数 记得传入参数 //处理obj是undefined null 的情况 if(obj===undefined || obj===null){ obj = window } //给obj添加一个方法 temFn:this obj.tempFn = fn //调用obj的temFn方法 传入args参数 const result = obj.tempFn(...args) //删除obj的temFn方法 delete obj.tempFn //返回方法的返回值 return result }