Function.prototype.myCall = function(context) {
if (typeof this !== 'function') {
return
}
let args = [...arguments].slice(1)
context = context || window || global
context.fn = this
let result = context.fn(...args)
delete context.fn
return result;
}
let person = {
name: 'test'
}
function setInfo(age, address) {
this.age = age
this.address = address
}
setInfo.myCall(person, '12', '北京')
console.log('结果', person)