Open goldEli opened 4 years ago
const dog = {
name: "xiaohuang",
say: function(msg) {
console.log(`${this.name}: ${msg}`)
}
}
const cat = {
name: "mongo"
}
Function.prototype.mycall = function(target, ...params) {
target.fn = this
target.fn(...params)
delete target.fn
}
dog.say.mycall(cat, "hi") // mongo: hi
模拟实现 call 方法