Michael, comments inside >> Here's a pattern that occurs frequently that I'm really >> curious about: >> >> new function() { >> // do stuff >> } >> >> Is the purpose of this just to provide local scope to the >> variables used? >> > > Yes, that is the one and only reason for it. > > >> Is there an equivalant syntax that may be >> more common? >> > > Yes, as others mentioned, ( function() { /*stuff*/ } )(); will do the trick > too, and is slightly more efficient. > is there somethign special about ( ... )(); ? I mean, how does this come from another example? > >> I intuitively wouldn't even think the code inside the >> function would get executed unless the whole thing >> was proceeded by "()", but obviously I'd be wrong. >> > > See if this helps: > > function Stuff() { > // do stuff > } > > var stuff1 = new Stuff(); // call the Stuff constructor > var stuff2 = new Stuff; // parens are optional > > >> What's really surprising is that I couldn't find any >> information about this technique in a google search. >> > > It's hard to search for. But it falls out from normal JavaScript syntax and > semantics. > > -Mike > > > _______________________________________________ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > > >
_______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/