I have this module pattern that stores a bunch of vars. I want to create a single function that can return any given var (the real module has real functions- this is just a striped down version).
var myObject = (function() {
var _savings = '100',
_year = new Date().getFullYear(),
_phone = '1-800-555-1234';
return {
getMe: function(param) {
return eval(param);
}
an example useage would be myObject.getMe('phone'); would poop out “1-800-555-1234”
I want to avoid the use of eval(), since its so evil.
Thanks!
In javascript,
object.fieldis equivalent toobject["field"].Now, the problem here is that you’ve created some private variables that don’t belong to an object, so accessing them will be tricky.
An alternative approach would be this: