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

Ambiguity when applying multiple mixins and what the Symbol.mixin property of the constructor prototype should be #3

Open
qubyte opened this issue Feb 15, 2018 · 1 comment

Comments

@qubyte
Copy link

qubyte commented Feb 15, 2018

The section on Symbol.mixin indicates that a property of the constructor prototpe will be set to the mixin applied. However, it's not obvious what this should be when multiple mixins are applied.

In other words, this snippet:

class C extends A with M1, M2, M3 {}

doesn't seem to mesh with the third line of this:

class C extends A with M {}
Object.getPrototypeOf(C).prototype.hasOwnProperty(Symbol.mixin); // true
Object.getPrototypeOf(C).prototype[Symbol.mixin] === M; // true

I'm a fan of this proposal by the way (I like mixins), and the sibling protocols proposal. Exciting to see them being considered as language features!

@justinfagnani
Copy link
Collaborator

justinfagnani commented Jul 11, 2018

Sorry for the delay here!

With multiple mixins, we'll get multiple objects on the prototype chain, each with their own [Symbol.mixin] property.

In the case of:

class C extends A with M1, M2, M3 {}

We'll have the prototype chain:

C' -> AwithM1_M2_M3' -> AwithM1_M2' -> AwithM1 -> A'

(where ' indicates ".prototype")

Each of AwithM1_M2_M3', AwithM1_M2', and AwithM1' will have a [Symbol.mixin] property, pointing to M3, M2, and M1 respectively.

Hope that answers the question. I'll try to clarify in the proposal.

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

2 participants