justinfagnani / mixwith.js

A mixin library for ES6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setup misunderstanding?

jedierikb opened this issue · comments

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!

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.