Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    32
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Need help understanding unusual syntax please

    I am working on a project based off the simile timeline, and am trying to understand the code so I can customize the interface. Many of the files in the API, such as this, contain functions that have me confused because of their syntax:

    Code:
    (function() {
         //stuff that the function does
    })();
    All I can guess is that it is a function within a function, but where is the outer function declared? I would expect something like:

    Code:
    function1 (function2() {
         //stuff that the function does
    })();
    Could someone please explain this to me?

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    728
    Thanks
    35
    Thanked 132 Times in 123 Posts
    wrapping a function declaration in parenthesis and following the whole expression with the function call ('()') calls the function as soon as it is defined.

  • Users who have thanked mrhoo for this post:

    bcatt (06-11-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •