#1
  1. web.graphic.print
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    Lancaster, CA USA
    Posts
    118
    Rep Power
    114

    Maybe this just isn't occurring to me


    Sorry if that's the case. I was wondering what this does:

    Code:
    (function () {some_stuff = "hello world"})();
    Like why have the parentheses around the function with the parentheses after that?
    Fire Minded
    Brent Bevans
    661.974.6771
    43654 Colony dr., Lancaster, CA 93536
    fire.minded.design@gmail.com
    http://www.fireminded.com
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    This is a function call of an anonymous function.

    The parantheses at the end signify a function call like always. And the outer parantheses are required to make the parser recognize the function stuff as a function expression (as opposed to a function statement).

    So you have an anonymous function which is immediately called. This pattern is often used to avoid global variables. In your particular example, however, it's completely useless, because some_stuff is declared as global (for whatever reason).
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo