Skip to content

Instantly share code, notes, and snippets.

@rayinla
Last active December 28, 2017 23:39
Show Gist options
  • Save rayinla/b362f4e5591d9d0fe9960464cefb1ae8 to your computer and use it in GitHub Desktop.
Save rayinla/b362f4e5591d9d0fe9960464cefb1ae8 to your computer and use it in GitHub Desktop.
var zombieOne = (function(){
//private variables
var firstName = "";
var lastName = "";
//private functions
function init(data){
firstName = data.firstName;
lastName = data.lastName;
}
function combineName(){
return firstName + " " + lastName;
}
function gerunding(action){
return firstName + " " + lastName + " " + "is" + " " + action;
}
//public functions
return {
getName: function(){
return combineName();
},
setName: function(data){
return init(data);
},
setAction: function(action){
return gerunding(action);
}
};
})();
var data = {firstName: "George", lastName: "Rooney" };
zombieOne.setName(data);
zombieOne.getName(); // "George Rooney"
zombieOne.setAction("walking");// "George Rooney is walking"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment