Skip to content

Instantly share code, notes, and snippets.

@ianldgs
Last active August 29, 2015 14:21
Show Gist options
  • Save ianldgs/6d0bfdd7f7a48b075737 to your computer and use it in GitHub Desktop.
Save ianldgs/6d0bfdd7f7a48b075737 to your computer and use it in GitHub Desktop.
Simulating traits on javascript
'use strict'
var trait = {}
trait.whatever = function (context) {
context.prototype.exec = function () {
console.log(this.i)
}
}
var A = function () {
this.i = 'teste _ A'
}
trait.whatever(A)
var B = function () {
this.i = 'teste _ B'
}
trait.whatever(B)
var a = new A();
var b = new B();
a.exec();
b.exec();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment