Created
August 20, 2019 14:54
-
-
Save alpenzoo/2d83444fcd1f17b522f0aea92b3d67c0 to your computer and use it in GitHub Desktop.
sample encapsulated variables, setters and getters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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