Problem with anonymous function and undefined members values
<p>I asked a question here:
<a href="http://stackoverflow.com/questions/4248222/extending-javascript-literal-object">Extending javascript literal object</a></p>

<p>which was solved because I forgot return. Now I didn't forget return and I got undefined again, why ?</p>

<pre><code>&lt;script&gt;
    var secretAgent = (function(){
      var person = {},
          firstName = "James",
          lastName = "Bond";
      person.WhoAreYou = function() {
        alert("My name is " + this.lastName + ", " + this.firstName + " " + this.lastName);
      };
      return person;
    })();
  &lt;/script&gt;

  &lt;script&gt;
    secretAgent.WhoAreYou();
  &lt;/script&gt;
</code></pre>

<p>Update: why mine doesn't work whereas I think I did the same thing as the one below that works:</p>

<p><a href="http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/" rel="nofollow">http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/</a></p>

<pre><code>//Revealing Module Pattern (Public &amp; Private)
var skillet = (function() {
    var pub = {},
        //Private property
        amountOfGrease = "1 Cup";

    //Public property   
    pub.ingredient = "Bacon Strips";

    //Public method
    pub.fry = function() {
        console.log( "Frying " + pub.ingredient );
    };

    //Private method
    function privateWay() {
        //Do something...
    }

    //Return just the public parts
    return pub;
}());

//Public Properties
console.log( skillet.ingredient ); //Bacon Strips

//Public Methods
skillet.fry();

//Adding a public property to a Module
skillet.quantity = 12;
console.log( skillet.quantity ); //12

//Adding a public method to a Module
skillet.toString = function() {
    console.log( skillet.quantity + " " +
                 skillet.ingredient + " &amp; " +
                 amountOfGrease + " of Grease" );
};

try {
    //Would have been successful,
    //but can't access private variable
    skillet.toString();
} catch( e ) {
    console.log( e.message ); //amountOfGrease is not defined
}
</code></pre>
