I have a JavaScript array inside a namespace like this:
app.collec.box = [];
and I have a function inside the same namespace like this:
app.init = function () {
var box = this.collec.box;
// ... code to modify box
};
I thought that setting a local variable equal to an object or object property was just a REFERENCE to the original, but it seems I am wrong, after changing the contents of the local box
variable inside my function, app.collec.box
does not change.
Please help, what am I doing wrong? how can I solve this?
Thanks in advance.
EDIT. This is the complete code.
var app = {
collec: {
box: [],
cache: []
},
init: function () {
var box = this.collec.box;
$.ajax({
url: 'file.json',
success: function (json) {
// Map JSON array to box array using Underscore.js _()map
box = _(json).map(function (o) {
return new Model(o);
});
}
});
}
};
app.init();