I'm still new to script writing and very new to Javascript. I have a couple simple scripts under my belt, but nothing that's ready for public consumption. I was looking at the Revealing Module Pattern from the API:Cookbook , which seems to be used by a number of the big names in script writing. I think I understand most of what it is doing (although I'm probably fooling myself about that). I copied it verbatim into an API script and ran it, and also I also ran it with Node.js (after changing the logs to console.logs). Here's the code as copied from the Cookbook: var myRevealingModule = myRevealingModule | | ( function () {
var privateVar = 'This variable is private' ,
publicVar = 'This variable is public' ;
function privateFunction () {
log (privateVar);
}
function publicSet (text) {
privateVar = text;
}
function publicGet () {
privateFunction ();
}
return {
setFunc: publicSet,
myVar: publicVar,
getFunc: publicGet
};
}());
log (myRevealingModule. getFunc ()); // "This variable is private"
myRevealingModule. setFunc ( 'But I can change its value' );
log (myRevealingModule. getFunc ()); // "But I can change its value"
log (myRevealingModule.myVar); // "This variable is public"
myRevealingModule.myVar = 'So I can change it all I want' ;
log (myRevealingModule.myVar); // "So I can change it all I want" When I run it I get the following output: "This variable is private" undefined "But I can change its value" undefined "This variable is public" "So I can change it all I want" I am wondering why I am getting the two "undefined" lines in the output. I believe this is due to the fact that privateFunction() has a log() call in it, but the call to getFunc() is wrapped in a log() call as well, and getFunc() doesn't return anything. It seems the call should be simply: myRevealingModule. getFunc (); // "This variable is private" Am I understanding this correctly? Thanks. -- John