justinfagnani / mixwith.js

A mixin library for ES6
Apache License 2.0
779 stars 58 forks source link

setup misunderstanding? #10

Closed jedierikb closed 8 years ago

jedierikb commented 8 years ago

Trying to get your library to work and could use some help.

I have an existing object.

export var aThing = function( ) {
};
aThing.prototype.sizzle = function( ) {
  console.log( "sizzle!" );
}

I want to add the functionality of an eventemitter library ( https://github.com/Olical/EventEmitter ) to an instance of aThing.

I tried the following:

let MyEventEmitterMixin = (eventEmitter) => class extends eventEmitter {};
export class aThing2 extends mix(aThing).with(MyEventEmitterMixin) {}
var at2 = new aThing2();
at2.sizzle();
//sizzle!
at2.addListener('sizzling', function() {console.log( "zzz";)} );
//Uncaught TypeError: at2.addListener is not a function

So, what I am doing wrong or what should the library be doing differently? Thanks!

jedierikb commented 8 years ago

I educated myself further about es6 classes. I now understand that I need to write my own methods in my mixin, and thereby benefit from the inheritance supers which are thereby made available.