Skip to content

Instantly share code, notes, and snippets.

@danilodeveloper
Last active September 8, 2016 01:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilodeveloper/c62303ff50bd6059dbfd to your computer and use it in GitHub Desktop.
Save danilodeveloper/c62303ff50bd6059dbfd to your computer and use it in GitHub Desktop.
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