Last active
December 16, 2015 15:08
-
-
Save DGuidi/5453188 to your computer and use it in GitHub Desktop.
super-simple JS class creation
This file contains 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
// 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