Skip to content

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.

// 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.

2 participants