Skip to content

Instantly share code, notes, and snippets.

@leocavalcante
Created February 21, 2015 18:36
Show Gist options
  • Save leocavalcante/72de0e8460d3091bdd56 to your computer and use it in GitHub Desktop.
Save leocavalcante/72de0e8460d3091bdd56 to your computer and use it in GitHub Desktop.
ES6 Mixins
var mixin = require('mixin');
class Cyclist {
ride() {
console.log(`${this.name} is riding`);
}
}
class Swimmer {
swim() {
console.log(`${this.name} is swimming`);
}
}
class Runner {
run() {
console.log(`${this.name} is running`);
}
}
class Triathlete extends
mixin(mixin(Cyclist, Swimmer), Runner) {
constructor(name) {
this.name = name;
}
letsDoIt() {
this.ride();
this.swim();
this.run();
}
}
let bob = new Triathlete('Bob');
bob.letsDoIt();
@jabaz
Copy link

jabaz commented Apr 26, 2016

Hi,
I'm getting this error, when using your code:

C:\Coding\test\index.js:26
this.name = name;
^

ReferenceError: this is not defined
at Triathlete (C:\Coding\test\index.js:26:9)
at Object. (C:\Coding\test\index.js:36:11)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment