fe-interview-handwrite
fe-interview-handwrite copied to clipboard
手写的myCall函数,有问题,如果context是数字或字符串,就报错了,要用Object()处理一下。
Function.prototype.myCall = function (context, ...paramsArr) { if (context === null || context === undefined) { context = window; } else { context = Object(context); // *** } const specialPrototype = Symbol("特殊属性Symbol"); context[specialPrototype] = this; const result = contextspecialPrototype; delete context[specialPrototype]; return result; };