I’m new to both JavaScript and YUI. In YUI library examples, you can find many uses of this construct:

(function() {
    var Dom = YAHOO.util.Dom,
    Event = YAHOO.util.Event,
    layout = null,
        ...
})();

I think the last couple of parentheses are to execute the function just after the declaration.

… But what about the previous set of parentheses surrounding the function declaration?

I think it is a matter of scope; that’s to hide inside variables to outside functions and possibly global objects. Is it? More generally, what are the mechanics of those parentheses?

7 Answers
7

Leave a Reply

Your email address will not be published. Required fields are marked *