Created
March 1, 2012 16:25
-
-
Save onlytracks/1951021 to your computer and use it in GitHub Desktop.
JavaScript Mixin Pattern
This file contains hidden or 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 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