Create a gist now

Instantly share code, notes, and snippets.

var Foo = {
init: function(who) {
this.me = who;
},
identify: function() {
return "I am " + this.me;
}
};
Foo.create = function() {
return Object.create(this);
}
var Bar = Foo.create();
Bar.speak = function() {
alert("Hello, " + this.identify() + ".");
};
Bar.create = function(param) {
var a = Object.create(this);
a.init(param);
return a;
}
var b1 = Bar.create('b1');
var b2 = Bar.create('b2');
b1.speak(); // alerts: "Hello, I am b1."
b2.speak(); // alerts: "Hello, I am b2."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment