J
John G Harris
Could you please refer to the proper section for our better understanding?
That applies to your previous reply as well.
It's the note in ECMA 262, section 13.1.2.
John
Could you please refer to the proper section for our better understanding?
That applies to your previous reply as well.
<snip>This is, of course, an arguable position, even a purely philosophical
position. If all the structures and mechanisms that facilitate
closures are in place why shouldn't a closure be considered to exists?
The same goes for the case where you preserve the inner function but
do not employ its environment (no other inner functions, formal
parameters or variables (or no uses of any of them in the inner
function)); if there is no way to determine whether the environment
was preserved (so no consequences either way) is it worth labelling it
a closure just because the necessary mechanism and structures may be
in place?
On Thu, 6 Aug 2009 at 05:10:39, in comp.lang.javascript, Richard
Cornford wrote:
<snip>
I think it's a terminology problem. We need two names for two different
things :
A proper closure occurs when an inner function is made callable from
outside its outer function, *and* the code of the inner function
accesses parameters or local variables of its outer function(s). The
standard requires this to work as in a traditional closure. There are no
options about this.
An empty closure occurs when an inner function is made callable from
outside its outer function, *and* the code of the inner function
accesses none of the parameters and local variables of its outer
function(s), *and* the inner function still carries the closure
machinery with it. The standard makes this an option. It can affect
performance and garbage collection, but this is (officially) not
observable behaviour of the program.
If, instead, the inner function does not carry the closure mechanism
with it then it is not a closure. The standard makes this an option as
well.
Incidentally, since Jorge has mentioned it, if inner functions cannot be
made callable from outside then there are no closures, only lexical
scopes. (As in Pascal).
On Aug 6, 5:05 am, kangax wrote:
Yes.
Yes.
<snip>
I am not sure that that last sentence should be included. This is one
place where John G Harris' "scoping rule !== closure" comes in.
Consider a programming language that is exactly like ECMAScript in
every respect except that the named properties of activation/variable
objects that are created during variable instantiation are deleted as
execution contexts are returned from. This is then a language in which
closures don't exist, yet the behaviour of an inner function called
(even very indirectly) before the function that contains it (within
which it was created) returns is identical to what it would be in
ECMAScript. That behaviour is explained by the language's scoping
rules alone and doesn't require closures.
For a closure I think you want to see both a function object _and_ its
environment outliving their normal (minimum, given the uncertain
nature of garbage collection) lifespan.
This is, of course, an arguable position, even a purely philosophical
position. If all the structures and mechanisms that facilitate
closures are in place why shouldn't a closure be considered to exists?
The same goes for the case where you preserve the inner function but
do not employ its environment (no other inner functions, formal
parameters or variables (or no uses of any of them in the inner
function)); if there is no way to determine whether the environment
was preserved (so no consequences either way) is it worth labelling it
a closure just because the necessary mechanism and structures may be
in place?
Earlier someone mentioned the question of whether if tree falls in a
forest, does it still makes a sound if there is nobody around to
perceive it. A pragmatic attitude might suggest that if you have no
way of knowing if/when a tree falls there is little point in expending
any effort worrying about how much noise it may make if it did.
Jorge said:1.- Contexts must be created, setup and inserted in the scope chain in
any case (the mechanism of identifier resolution in accordance with
the scoping rules).
2.- Sometimes a function's context can't be destroyed upon exiting the
function : when at that point in time there still exists yet another
function whose context points to, includes, has access to, uses it:
that is necessarily the context of an outliving inner function. It's
then that we say that a closure has been created.
3.- There's no "closure machinery". A closure is the absence of
destruction of a context.
<snip>That binding might be trivial, if the code has no free variables. You
can argue that it isn't really a closure then, but that's not really
important.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.