Skip to content

Instantly share code, notes, and snippets.

@andineck

andineck/1 readme.md

Last active Aug 29, 2015
Embed
What would you like to do?
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