Function.prototype.myApply = function (thisArg, argArray) {
const fn = Symbol('fn')
thisArg[fn] = this
const res = thisArg[fn](...argArray)
delete thisArg[fn]
return res
}
const person = {
name: 'mandy',
age: 21
}
function fun(numA, numB) {
console.log(this);
console.log(numA, numB);
return numA + numB;
}
const result = fun.myApply(person, [1, 2]);
console.log('myApply - result:' + result);
const result2 = fun.apply(person, [3, 4]);
console.log('apply - result:' + result2);
</script>
.
.
.