Skip to content

Instantly share code, notes, and snippets.

@DGuidi
Last active December 16, 2015 15:08
Show Gist options
  • Save DGuidi/5453188 to your computer and use it in GitHub Desktop.
Save DGuidi/5453188 to your computer and use it in GitHub Desktop.
super-simple JS class creation
// from: http://davidwalsh.name/javascript-objects-deconstruction
var Foo = {
init: function(who) {
this.me = who;
},
identify: function() {
return "I am " + this.me;
}
};
var Bar = Object.create(Foo);
Bar.speak = function() {
alert("Hello, " + this.identify() + ".");
};
var b1 = Object.create(Bar);
b1.init("b1");
var b2 = Object.create(Bar);
b2.init("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