Skip to content

Instantly share code, notes, and snippets.

@onlytracks
Created March 1, 2012 16:25
Show Gist options
  • Save onlytracks/1951021 to your computer and use it in GitHub Desktop.
Save onlytracks/1951021 to your computer and use it in GitHub Desktop.
JavaScript Mixin Pattern
var Person = function(name) {
this.name = name
}
var GreeterMixin = function() {
this.greet = function(name) {
return "Hello " + name + ", I am " + this.name
}
}
GreeterMixin.call(Person.prototype)
var john = new Person('John')
console.log(john.greet('Pete')) // Hello Pete, I am John
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment