Javascript Module pattern with DOM ready

Posted by dego89 on Programmers See other posts from Programmers or by dego89
Published on 2014-06-09T14:36:47Z Indexed on 2014/06/09 15:40 UTC
Read the original article Hit count: 204

Filed under:
|

I am writing a JS Module pattern to test out code and help me understand the pattern, using a JS Fiddle. What I can't figure out is why my "private methods" on line 25 and 26, when referenced via DOM ready, have a value of undefined.

JSFiddle

Code Sample:

var obj = {
    key: "value"
};

var Module = (function () {

  var innerVar = "5";

  console.log("obj var in Module:");
  console.log(obj);

function privateFunction() {
    console.log("privateFunction() called.");
    innerFunction();

    function innerFunction() {
        console.log("inner function of (private function) called.");
    }
}

function _numTwo() {
    console.log("_numTwo() function called.");
}
return {
    test: privateFunction,
    numTwo: _numTwo

}


}(obj));


$(document).ready(function () {
    console.log("$ Dom Ready");
    console.log("Module in Dom Ready: ");
    console.log(Module.test());
});

© Programmers or respective owner

Related posts about JavaScript

Related posts about jQuery