I have a JavaScript array inside a namespace, for example:
app.collec.box = [];
and I have a function inside the same namespace:
app.init = function () {
var box = this.collec.box;
};
I thought that setting a local variable equal to an object or an object was just a reference to the original, but it seems like I'm mistaken that changing the contents of a local variable boxinside my function app.collec.boxdoes 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) {
box = _(json).map(function (o) {
return new Model(o);
});
}
});
}
};
app.init();
source
share