Skip to content

Instantly share code, notes, and snippets.

@anova
Created October 13, 2014 12:15
Show Gist options
  • Save anova/a7d2e29c2bbd4961f2a8 to your computer and use it in GitHub Desktop.
Save anova/a7d2e29c2bbd4961f2a8 to your computer and use it in GitHub Desktop.
Javascript module pattern with immediate function call.
//http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript
var User = (function(){
var _Name, _Surname;
return {
getName : function(){
return _Name;
},
setName : function(value) {
if(value !== undefined){
_Name = value;
}
},
getSurname : function(){
return _Surname;
},
setSurname : function(value) {
if( value !== undefined) {
_Surname = value;
}
},
getFullName : function(){
return _Name + ' ' + _Surname;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment