Function.prototype.myCall = function (curThis) {
if (typeof this !== "function") {
throw new Error();
}
if (curThis === null || curThis === undefined) {
curThis = window;
}
switch (typeof curThis) {
case "number":
curThis = new Number(curThis);
break;
case "string":
curThis = new String(curThis);
break;
case "boolean":
curThis = new Boolean(curThis);
break;
default:
curThis = curThis;
break;
}
curThis.func = this;
const test = curThis.func(...[...arguments].slice(1));
delete curThis.func;
return test;
};
function fn(a) {
console.log(a);
console.log(this);
}
fn.call([]);
fn.myCall([]);