1

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?

1 Answer 1

2

Change alert(data) to alert(this.data).

Sign up to request clarification or add additional context in comments.

1 Comment

yeah, no idea, I would expect undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.