var obj = {
message: 'My name is: '
}
function getName(firstName, lastName) {
console.log(this.message + firstName + ' ' + lastName)
}
Function.prototype.tocall=function(...arg){
let one = [...arg][0]
one.fn=this//指向调用tocall的函数
let result = one.fn(...[...arg].slice(1))//执行前面的函数并传入后面的参数 ,去头嘎嘣脆 ,鸡肉味
delete one.fn //删除增加的属性
return result //返回当前方法
}
Function.prototype.toapply=function(...arg){
let one = [...arg][0]
one.fn=this
let result = one.fn(...[...arg][1])
delete one.fn
return result
}
getName.toapply(obj,["abc","66666"])