Created
February 21, 2015 18:36
-
-
Save leocavalcante/72de0e8460d3091bdd56 to your computer and use it in GitHub Desktop.
ES6 Mixins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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