Created
April 21, 2013 21:40
-
-
Save nulltier/5431179 to your computer and use it in GitHub Desktop.
cool example of javascript inheritance from http://alexsexton.com/blog/2013/04/understanding-javascript-inheritance/
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
var defaults = { | |
zero: 0, | |
one: 1 | |
}; | |
var myOptions = Object.create(defaults); | |
var yourOptions = Object.create(defaults); | |
// When I want to change *just* my options | |
myOptions.zero = 1000; | |
// When you wanna change yours | |
yourOptions.one = 42; | |
// When we wanna change the **defaults** even after we've got our options | |
// even **AFTER** we've already created our instances | |
defaults.two = 2; | |
myOptions.two; // 2 | |
yourOptions.two; // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment