Luke Scott (2015-02-12T18:47:44.000Z)
d at domenic.me (2015-02-17T20:24:30.097Z)
On Feb 12, 2015, at 10:27 AM, Andrea Giammarchi <andrea.giammarchi at gmail.com> wrote: > This is what I am using now: https://gist.github.com/lukescott/36453a75c39c539f5c7d <https://gist.github.com/lukescott/36453a75c39c539f5c7d> Based on the gist I provided, this is how I would envision the ES7 version looking like: ```js trait Trait1 { method1() {} } trait Trait2 { method2() {} } trait Trait3 { mixin Trait2; method3() {} } Trait3 hasTrait Trait2 // true Trait3 hasTrait Trait1 // false class Foo { mixin Trait1; } Foo hasTrait Trait1 // true Foo hasTrait Trait2 // false class Foo2 extends Foo {} Foo2 hasTrait Trait1 // true Foo2 hasTrait Trait2 // false class Foo3 extends Foo { mixin Trait2; } Foo3 hasTrait Trait1 // true Foo3 hasTrait Trait2 // true class Bar { mixin Trait3; } Bar hasTrait Trait1 // false Bar hasTrait Trait2 // true Bar hasTrait Trait3 // true ``` As far as conflict resolution goes, you could go by trait order (last one wins), or simply throw an exception when mixing in two traits with the same methods. A conflict would look like this: ```js trait Trait1 { someMethod() } trait Trait2 { someMethod() } class Foo { mixin Trait1, Trait2; } ``` OR ```js class Foo { mixin Trait1 mixin Trait2; } ``` But this would not be a conflict: ```js trait Trait1 { someMethod() } trait Trait2 { mixin Trait1; someMethod() // Override method from Trait1 } class Foo { mixin Trait2; } ``` PHP has traits, but has a way to resolve conflicts by specifying which method should be used. I would keep it simple and make conflicts an error outright or last one wins. Most use cases for traits is including functionality that can’t be inherited where you would have to copy and paste methods otherwise.