Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WhaleMr opened this issue Oct 1, 2022 · 0 comments

Comments

@WhaleMr
Copy link

WhaleMr commented Oct 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant