Message from discussion closures, what are they good for?
From: codeHan...@yahoo.ca (rh)
Subject: Re: closures, what are they good for?
Date: 28 Apr 2003 16:30:10 -0700
References: <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org>
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1051572611 25406 127.0.0.1 (28 Apr 2003 23:30:11 GMT)
NNTP-Posting-Date: 28 Apr 2003 23:30:11 GMT
"Richard Cornford" <Rich...@litotes.demon.co.uk> wrote in message news:<email@example.com>...
> Richard Cornford wrote in message ...
> - as it does considerably less work on each invocation of the inner
> function. However it does now assume that the reference to the function
> that is stored in the public static member of the constructor is not
> changed by other scripts.
> Although, storing a reference to a private method of an object instance
> will prevent garbage collection of the object instance (at least until
> the page unloads) so the 'tempFunc' array (or the function reference
> within it) might have to be actively nulled if the cyclic reference to
> activeX and HTML element problem that Steve van Dongen raised is likely
> to be significant.
(My version of the thread currently looks as:
\-11 Lasse Reichstein Nielsen 22 Apr 2003
\-12 Richard Cornford 27 Apr 2003
\-13 Richard Cornford 27 Apr 2003
\-14 Richard Cornford 28 Apr 2003
missing my prior post, and apparently one from Steve van Dongen, so I
may not be tracking correctly.)
Your extension here and above is interesting and instructive. Not sure
how practical or necessary it is though.
Another objection that may well arise is that you appear to have
converted private functions into a public functions (which I also did,
perhaps, by handing off the reference to setInterval -- but I
considered it trusted) by adding the accessible references to the
That suggests to me that intervalEvent really ought to be
this.intervalEvent, i.e., a public function to begin with, just so
everything stays clear and consistent regarding public vs. private.
With that change you should be able to store references to the primary
objects, rather than references directly to inner functions, and still
be able to get to the handler through the eval of a string generated
by the .toString invocation.
That doesn't solve the problem of creating additional references,
(By the way, thanks for cleaning up the slightly brain-dead iteration
control in my example. I debated about fixing it prior to posting, but
wasn't capable at the time ;-)).