Module Pattern (The Good Parts of JS)



I am penetrating the world of programming in JS, I have handled some languages but not in depth. I was testing the sample code that show in autorun function. and I doubt arose when tested in the interpreter. He was running this code:

Reviewing autorun function //
var myLibrary = (function() {
var foo = ‘Module Pattern’;
var ver = ‘ver 1.0’;

var add = function(a , b){
return a + b;

return {
myMessage : function(){
return foo + ‘ ‘ + ver ;
console.log( myLibrary.myMessage() );

When you run this code I get the error only add that the function is not declared, which is perfectly valid. But on the next line when he made the call to me in theory myLibrary.myMessage "Module Pattern ver 1.0" should appear.

My question is generated when I see this behavior. My question then is:
What happens in the interpreter to not screen out what method returns the public?

In advance thanks.