Skip to content

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

@WhaleMr

Description

@WhaleMr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions