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

avoid Array.from and Reflect #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

graingert
Copy link

No description provided.

a.__proto__ = b;
});
var getPrototypeOf = Object.getPrototypeOf || (function getPrototypeOf(a)) {
return a.__proto__;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't imagine a case where getPrototypeOf doesn't exist but __proto__ does. getPrototypeOf is from ES5, so it either exists, or there's no way to polyfill it AFAIK.

function ExtendableBuiltin(){
// Not passing "newTarget" because core-js would fall back to non-exotic
// object creation.
var instance = Reflect.construct(cls, Array.from(arguments));
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
var instance = new (Function.prototype.bind.apply(cls, arguments))();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general concern with approaches like this is that .bind is known to be slow. Most things optimize this like statements like https://github.com/zloirock/core-js/blob/master/modules/es6.reflect.construct.js#L29, so larger code like that was what I was trying to avoid.

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

Successfully merging this pull request may close these issues.

None yet

2 participants