Klaus is right, Here's an article about closure causing leaks http://www.javascriptkit.com/javatutors/closuresleak/index.shtml
On Dec 30, 4:38 am, "Alexandre Plennevaux" <aplennev...@gmail.com> wrote: > Klaus, you got me: frankly i have no "real" idea what is the purpose > of enclosure. > That's abstract art to me. i just read in several places that it's > good to use it, so i trust my sources, do it and move on. Not that i'm > proud of it, but, to use a metaphor, one does not need to know the > internals of a car in order to be able to drive it, although it surely > is a valuable knowledge if one wants to keep its car in a good state ! > Yet, since the car changes every six months, it's just up to you, > wheather you're driven by the pure developer's passion or by consumer > pragmatism. > > On Tue, Dec 30, 2008 at 1:28 PM, Klaus Hartl <klaus.ha...@googlemail.com> > wrote: > > > On 30 Dez., 08:45, "Alexandre Plennevaux" <aplennev...@gmail.com> > > wrote: > >> "JavaScript enclosures"? > > >> i think it has to do with encapsulating your code inside a function so > >> that all vars are inside the function's scope, so not cluttering the > >> global namespace. > >> This, to avoid memory leak. > > > Are you implying that global variables do leak memory? There are good > > reasons to not clutter the global namespace but I don't believe > > avoiding leaks is one of them. > > > Actually you do increase the chance to create leaks in IE if you use > > closures under certain circumstances. > > > --Klaus