Passing object references between modules
<p>I am rather new to javascript and trying to learn some of the best practices.  I am unclear as to why I can't access the ctx reference in the following code.  The log outputs a context2d reference from myApp.init().  Can I not expose a private object variable in the return statement of the myApp module?  I thought I was beginning to understand the basics of this language but am getting frustrated by this seemingly simple concept.  Thanks for your help.</p>

<pre><code>window.onload = function () {
    myApp.init();
    console.log(myApp.ctx);        // logs undefined
};

var myApp = (function () {    

    var canvas,
        ctx,
        init = function () {
            canvas = document.getElementById("canvas");
            ctx = canvas.getContext('2d');
            console.log(ctx);        // logs valid context2d object
        };

    return {
        init : init,
        ctx  : ctx
    };

}());

myApp.board = (function () {

    var ctx = myApp.ctx;

    return {
        ctx : function () { console.log(ctx); }   // logs undefined
    };

}());
</code></pre>
