Loading ...
Sorry, an error occurred while loading the content.

Advantage of having anonymous function executing immediately

Expand Messages
  • kashodiya
    What is the real advantage of this style of programing? ... (function() { YAHOO.example.app = { ... }; //Call loader the first time var loader = new
    Message 1 of 2 , Feb 5 2:50 PM
    • 0 Attachment
      What is the real advantage of this style of programing?
      ----------------------------

      (function() {
      YAHOO.example.app = {
      ...
      };

      //Call loader the first time
      var loader = new YAHOO.util.YUILoader({
      ...
      onSuccess: function() {
      ...
      }
      });
      loader.insert();
      })();

      ----------------------------
      For full code go to:
      http://developer.yahoo.com/yui/examples/layout/assets/js/main.js
    • Adam Moore
      ... The loader variable is scoped to the anonymous function. It would be global if the function wrapper were omitted, which is something we like to avoid.
      Message 2 of 2 , Feb 5 3:03 PM
      • 0 Attachment
        On Thu, Feb 05, 2009 at 10:50:40PM -0000, kashodiya wrote:
        > What is the real advantage of this style of programing?

        > ----------------------------
        >
        > (function() {
        > YAHOO.example.app = {
        > ...
        > };
        >
        > //Call loader the first time
        > var loader = new YAHOO.util.YUILoader({
        > ...
        > onSuccess: function() {
        > ...
        > }
        > });
        > loader.insert();
        > })();

        The loader variable is scoped to the anonymous function. It would be
        global if the function wrapper were omitted, which is something we
        like to avoid.

        -Adam
      Your message has been successfully submitted and would be delivered to recipients shortly.