call 分析
代码
Function.prototype.call = function call(context, ...prams) {
context == undefined ? context = window : null;
if (!/^(object|function)$/.test(typeof context)) {
if (/^(symbol|bigint)$/.test(typeof context)) {
context = Object(context)
} else {
context = new context.constructor(context)
}
}
let key = Symbol(''),
result;
context[key] = this;
result = context[key](...prams);
delete context[key]
return result
}
练习
答案