Function.prototype.mycall = function (ctx, ...args) {
ctx = ctx === undefined || ctx === null ? globalThis : Object(ctx)
const fn = this
const key = Symbol('temp')
// console.log(333, key)
Object.defineProperty(ctx, key, {
enumerable: false,
value: fn
})
const result = ctx[key](...args)
delete ctx[key]
return result
}
function method(a, b) {
console.log(this, a, b)
return a + b
}
console.log(method.mycall(111, 1, 2))
console.log(method.call(111, 1, 2))