Function.prototype.myCall = function(context, ...args) {
context = context || window;
let fn = Symbol();
context[fn] = this;
const result = context.fn(...args);
delete context.fn;
return result;
}
let Person = {
name: 'Tom',
say(age) {
console.log(this)
console.log(`我叫${this.name}我今年${age}`)
}
}
Person1 = {
name: 'Tom1'
}
Person.say.call(Person1,18)
Function.prototype.myApply = function (context, args) {
context = context || window;
let fn = Symbol();
context[fn] = this;
const result = context.fn(...args);
delete context.fn;
return result;
};