Wednesday, 5 October 2016

javascript - What do parentheses surrounding an object/function/class declaration mean?

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?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...