[Dojo-interest] Re: Closures and memory usage (was: Widgets and
memory issues)
Ed
ednotover at gmail.com
Mon Feb 5 15:05:41 MST 2007
On 2/2/07, Ed <ednotover at gmail.com> wrote:
>
>
> From: "sam foster" <potatosculptor at gmail.com >
>
>
> I often use this pattern to get temporary scope:
> > (function() {
> > var someScopedVar = 'whatever';
> > // ...
> > })()
> >
> > particularly inside loops where scope can really catch you out.
>
>
> For something like that, I'd define the function outside the loop and then
> have the loop call the function. Again, it's a case where if I know I can
> write the code to prevent the interpreter from doing something foolish, I
> do. (If the function is defined in the loop, a dumb interpreter might
> redefine that function for each and every pass through the loop.)
>
I tripped across an interesting idea today - see point 6 here:
http://isaacschlueter.com/2007/01/lessons-in-javascript-optimization/
The idea is to manage the private variables via a 'with' statement instead
of a function definition. Admittedly, it is a less flexible approach - you
don't get a new scope, so you have to pre-define all your private variables
in the 'with' object.
Ed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dojotoolkit.org/pipermail/dojo-interest/attachments/20070205/6506f298/attachment-0001.html
More information about the Dojo-interest
mailing list