Skip to content

Instantly share code, notes, and snippets.

@andineck
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andineck/d2984e008c873f670076 to your computer and use it in GitHub Desktop.
Save andineck/d2984e008c873f670076 to your computer and use it in GitHub Desktop.
Javascript Member Variables done properly

javascript member variables

know the difference between shared and instance specific member variables in javascript.

// 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