0

This is my bootstrap:

LanesBoard2010 = (function () {
    var appRoot = this;

    appRoot.deferredLoad = new Object(); //holding jqxhr states
    appRoot.utils = {}; //namespace for helper classes
    appRoot.models = {};
    appRoot.data = (function () { } ()); //store data from webservices here
    appRoot.app = (function () { } ()); //ViewModel
}();

After some initialisation i run my deferred app loader:

function appStart() {
    appRoot.deferredLoad.app = $.getScript('../TaskBoardContent/Script/app/lanesboard.js');
    $.when.apply($, appRoot.deferredLoad.app).then(function () {
        if (window.console)
            if (debug)
                console.log('application lanesdashboard was loaded successfully\n');
    }, function () {
        if (window.console)
            if (debug)
                console.log('fatal error: unable to load application lanesdashboard\n');
    });
};

Now i need to access appRoot, or more general, modify the properties of LanesBoard2010.

the following statement is from my lanesboard.js. It just fails after the first console.log, as i can see both variable names are unknown:

(function () {
    if (window.console)
        if (true) {
            console.log('App has been initialised successfully');
            console.log('Status of app access 1: ' + appRoot);
            console.log('Status of app access 2: ' + LanesBoard2010);

        }
}());

May sound stupid, but how can i safely access my variables? Is there any best practice? How would you do this?

1 Answer 1

0

What exactly is your question? How you can prevent to use an undefined variable?

You can either define it before any calls and initialise it to null (var appRoot = LanesBoard2010 = null) or check the variable before you call console.log() (if (appRoot) console.log('Status of app access 1: ' + appRoot);).

I normally use the first suggestion. I first set all my caches to null, create the autocompletes, then use $.ajax to load them and when loaded, update the autocomplete sources.

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

1 Comment

no, i cannot access my vaiables. just now found the solution: stackoverflow.com/questions/10330457/…

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.