I'm having trouble figuring out namespaces for a project.
My Namespace looks like this thus far:
var NS = NS || {};
NS.Utils = NS.Utils || {};
NS.Models = NS.Models || {};
NS.Views = NS.Views || {};
NS.App = (function () {
this.data = "hello";
var init = function () {
alert(data);
};
return {
data: this.data,
init: init,
};
} ());
And then I initialize it with this:
(function ($, global, data) {
$(global).click(function() {
NS.App.init();
});
NS.App.data = "hello testing";
NS.App.init();
}(jQuery, window, data));
But for some reason, the Second, NS.App.init() call does not use the updated NS.App.data variable. How can I fix this?
Also, how can I reference other namespaces inside of NS.App? For example, if I want to use NS.Utils inside of NS.App?