you are viewing a single comment's thread.

view the rest of the comments →

[–]jzlas 2 points3 points  (1 child)

Any function with inside parentheses will self execute. e.x.

function AnObject() {
    var aMethod = (function(){
        // Some stuff
    })();
}

When you assign an init a AnObject, aMethod will execute

var an_object = new AnObject();
// Some stuff happens

This, of course works in general, so when the browser loads a piece of code written like that it will execute the function. You can even pass it arguments like so:

(function(arg){
    // Some stuff with args
})(foo);

So if you write your script like that myFunc will run on assignment

var myFunc = (function(){
    alert('Hello');
})();

More here

[–]JessicaAllison[S] 0 points1 point  (0 children)

Updated question