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

safeguard against duplicate on/using calls #2

Closed
wants to merge 1 commit into from

Conversation

brigand
Copy link

@brigand brigand commented Mar 11, 2015

My understanding is that calling on/using more than once will cause the second call to influence new instances of the first class it's used on.

This is just a check to identify programmer error.

@brigand
Copy link
Author

brigand commented Mar 11, 2015

Just to clarify, the case is something like this:

// example.js 
require('es6-shim');
const traits = require('./es6-traits.min.js');
const {on, using} = traits();

const T1 = {
  foo: () => 'T1'
};

class A extends (on (Object), using (T1)) {
    bar(){
        console.log('A', this.foo());
    }
}

const T2 = {
  foo: () => 'T2'
};

class B extends (on (Object), using (T2)) {
    bar(){
        console.log('B', this.foo());
    }
}

var a = new A();
var b = new B();

a.bar();
b.bar();

Likely expected:

A T1
B T2

Actual:

A T1
B T1
npm i es6-shim && babel example.js | node

@brigand
Copy link
Author

brigand commented Mar 11, 2015

After reading the code a couple more times, I now see that this is what Symbol.toStringTag is intended to solve. A bit odd, but functioning.

@brigand brigand closed this Mar 11, 2015
@gsklee
Copy link
Owner

gsklee commented Mar 11, 2015

@brigand Yep, it's essentially naming the mixins; otherwise, it'll be difficult to tell whether two objects are the same mixin or not.

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