Looking at the Javascript revealing module pattern below, the variable "defaultValue" does not update and needs a getter to access and updated value - explained here.
Why is it then, that an array (e.g. defaultArray) does update and can be accessed without a specific getter?
Example Code:
var go = function () {
var defaultValue = null;
var defaultArray = [];
var setDefaultValue = function (newObj) {
for (var i = 0; i < 5; i++) {
if (i == 2) {
defaultValue = newObj;
defaultArray.push(newObj);
}
}
};
var getDefault = function () {
return defaultValue;
};
return {
defaultValue: defaultValue,
setDefaultValue: setDefaultValue,
getDefault: getDefault,
defaultArray: defaultArray,
};
};
window.onload = function () {
var ans = new go();
ans.setDefaultValue({ test: 'ok', unos: 123 })
// At this point, defaultArray has updated, but defaultValue has not
var thisWillBeNull = ans.defaultValue;
var thisWillHaveAValue = ans.defaultArray;
// Can get the value
var newDefault = ans.getDefault();
};