Function.prototype._call = function(target,...args) {
target.fn = this
let result = target.fn(...args)
delete target.fn
return result
}
Function.prototype._apply = function(target,arr) {
target.fn = this
let result = target.fn(...arr)
delete target.fn
return result
}
Function.prototype._bind = function(target,...args) {
let that = this
return function(){
target.fn = that
let result = target.fn(...args)
delete target.fn
return result
}
}
name = "李四"
function getName(name,age) {
console.log(this.name,name,age)
}
let obj = {
name:"张三",
age:18
}
getName("王五",7)
console.log("call")
getName._call(obj,"xiao",10)
console.log("apply")
getName._apply(obj,["da",9])
console.log("bind")
let getWo = getName._bind(obj,"wo",8)
getWo()
console