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

Question on Object oriented Programming in JS

Expand Messages
  • jiangqq
    Hi All When I looked at ExtJS source code, I found something strange. could anyone here explain to me? In ext-base.js file they wrap the all code inside:
    Message 1 of 2 , Jul 7, 2008
      Hi All

      When I looked at ExtJS source code, I found something strange.


      could anyone here explain to me?


      In ext-base.js file
      they wrap the all code inside:


      (function() {
      ...
      ...
      ...


      )()


      What is that mean?


      Thanks
      Steven
    • Tim Sabin
      This is defining a function then immediately invoking it. Normally you define a function function myFunc () { ... } and you invoke it myFunc (); Here, first
      Message 2 of 2 , Jul 8, 2008
        This is defining a function then immediately invoking it.

        Normally you define a function
        function myFunc () {
        ...
        }
        and you invoke it
        myFunc ();

        Here, first they defined an anonymous function:
        function () {...}
        Then, they invoke it immediately:
        (function () {
        ...
        }) ();

        This is only one of 2 ways that an anonymous function is of any use.

        --Tim Sabin


        > Hi All
        >
        > When I looked at ExtJS source code, I found something strange.
        >
        >
        > could anyone here explain to me?
        >
        >
        > In ext-base.js file
        > they wrap the all code inside:
        >
        >
        > (function() {
        > ...
        > ...
        > ...
        >
        >
        > )()
        >
        >
        > What is that mean?
        >
        >
        > Thanks
        > Steven
        >
        >
        >
        >
        >
        > ------------------------------------
        >
        > Visit http://aiaiai.com for more groups to joinYahoo! Groups Links
        >
        >
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.