Skip to content

Instantly share code, notes, and snippets.

@alpenzoo
Created August 20, 2019 14:54
Show Gist options
  • Save alpenzoo/2d83444fcd1f17b522f0aea92b3d67c0 to your computer and use it in GitHub Desktop.
Save alpenzoo/2d83444fcd1f17b522f0aea92b3d67c0 to your computer and use it in GitHub Desktop.
sample encapsulated variables, setters and getters
function myfunc(){
var data = {
name:'',
age:0,
roles:[],
prefs:{
timezone:1,
theme:'light',
lng:'en'
}
};
return {
setName: function (arg){
this.name = arg;
return this.name;
},
setAge: function (arg){
this.age = arg;
return this.age;
},
getAsString: function () {
return this.name+ " is " +this.age + " years old.";
}
}
}
var myvar = myfunc();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment