fe-interview-handwrite icon indicating copy to clipboard operation
fe-interview-handwrite copied to clipboard

手写的myCall函数,有问题,如果context是数字或字符串,就报错了,要用Object()处理一下。

Open WhaleMr opened this issue 3 years ago • 0 comments

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; };

WhaleMr avatar Oct 01 '22 13:10 WhaleMr