Javascript Module pattern with DOM ready
- by dego89
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());
});