know the difference between shared and instance specific member variables in javascript.
Last active
August 29, 2015 14:19
-
-
Save andineck/d2984e008c873f670076 to your computer and use it in GitHub Desktop.
Javascript Member Variables done properly
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
// data is shared between all MyModule Instances (probably not intended to do so) | |
// so if one instance modifies data, all other instances share the modified data object | |
MyModule.prototype.data = {super: 'clever'} | |
// intended member variable, that is not shared between the myModule Instances | |
MyModule.prototype.init = function() { | |
this.data = {super: 'clever'} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment