From: Richard Cornford on
Ry Nohryb wrote:
>On Jun 1, 11:41 am, Richard Cornford wrote:
>> On Jun 1, 9:50 am, Ry Nohryb wrote:
>> > On Jun 1, 8:41 am, Richard Cornford wrote:
>> >>> What am I missing ?
>>
>> >> Apparently, and at minimum, the difference between the two
>> >> subjects.
>>
>> > Apparently, yes. What's the difference ?
>>
>> > function f () {}
>> > var Clase= f();
>>
>> > vs.
>>
>> > var Clase = (function f () {})();
>>
>> > � That difference ?
>>
>> Beyond one of them being the subject of this thread and the other
>> not?
>
> Yes. Because if -as you said- "Douglas Crockford appears to be
> responsible for inventing the technique for emulating private
> instance members in JavaScript", and, -as you said- "I (you)
> posted the first (to the best of my knowledge) example of using
> an immediate call to an anonymous function expression intended
> to achieve some notion of 'private' (private static 'class'
> members in that case)", your "first (to the best of my
> knowledge) example" was an application of his invention, which
> means that his invention must have happened prior to your example.
>
> The point being, wasn't Crockford at that point clever enough
> already, or, let's say, better, curious, inventive, creative enough
> to have never done that ("that" being the use of an immediate call
> in order to create the closure) himself ?

"Wasn't Crockford ... clever ... , curious, inventive, enough to have
never down that ... himself?" What are you asking there? Being too
clever, inventive, etc. to have done something seems like an odd idea
(at least if that something isn't an obviously bad idea).

> Is this your understanding ? That he
> never devised it until after you told/showed him ?

How can anyone know what may have been in the mind of someone else at
some point in the past? Is there any evidence of Douglas Crockford
publishing any examples of an inline call to a function expression, at
all or as a generalisation of his method for emulating private instance
members?

I first published my use of an inline call to a function expression in a
thread with the subject "Static class variable creation? Options" on the
23rd of April 2003. My first post in that thread stated the 'accepted
wisdom' of the day; that the only possibility for 'static' class
members is to create them as properties of the constructor. You will
notice that Douglas Crokford also responded to that OP, with pretty much
the same advice.

Laurent Bugnion later pointed out that there was (believed to be, and
with his having full knowledge of Crockford's technique for private
instance members) no possibility for 'private static' members in
javascript. This started me thinking, that there must be some way of
bumping Crokford's technique up a level (or generalising it) to provide
'private static' members, and churning that over I eventually hit upon
the idea of using an inline call to a function expression wrapped around
the constructor to form a closure around the constructor instead of
inside it. So I published that latter that day.

Now, if you assume that Douglas Crockford had been over this ground
previously you have to wonder why he did not mention the possibility in
his post in that thread (even if he had never previously had reason to
mention it), or as a correction to Laurent Bugnion's post. A very
reasonable explanation for that is that the either he idea of
generalising his technique for creating private instance method had not
occurred to him (maybe because the need had never arisen), or he had
never managed to think up a viable method for doing so.

Either of those possibilities seems to preclude his having had the idea
of using an inline call to a function expression because that is the
method that bumps his technique up to the 'class' level, and because
once I had employed an inline call to a function expression to achieve
some notion of 'private' it immediately occurred to me that there were
numerous other 'encapsulation' applications for the construct (as can be
witnessed from the numerous versions I posted to the group over the next
few weeks). So, if inline call to the function expression, used to
achieve some notion of 'private' had occurred to Douglass Crokford
independently of his technique for emulating private instance members in
javascript then it really wouldn't have taken him long to put the two
together, and so would be responding to 'static class variable' posts
with examples of both public and private.

>> But what do either of those have to do with Douglas Crockford's
>> observation that (classical OO style) private instance members
>> could be emulated in javascript by forming a closure using a
>> constructor? I don't see any - new - operators or any indication
>> of anything that could be considered 'instances of a class',
>> with or without 'private' members.
>
> But you can see the pattern where the constructor ("Clase") is
> the returned value of a function call:

See it? I invented it. ;-)

> the function call that is required to create the closure to
> hold the private/privileged resources, which is the matter
> we're talking about. I guessed that would suffice you, or
> do I really need me to write a real constructor for you to
> get it ?

If you write a constructor then you have an example of Douglass
Crockford's technique for emulating private instance members in
javascript. Showing that very specific thing would serve to highlight
the difference between it and the two very general things; a closure
(your first example) and (less general) the use of an inline call to a
function expression being used to form a closure (your second example).

Richard.

From: Richard Cornford on
On Jun 3, 1:30 am, Richard Cornford wrote:
<snip>
> I first published my use of an inline call to a function
> expression in a thread with the subject "Static class variable
> creation? Options"
<snip>

I have no idea how the word "Options" found its way in there. It was
not intentional. I had intended to include a google groups URL for the
thread, it is here:-

<URL: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/dea2a95df1e355ca
>

Richard.
From: Ry Nohryb on
On Jun 3, 2:30 am, "Richard Cornford" <Rich...(a)litotes.demon.co.uk>
wrote:
> (...)
> I first published my use of an inline call to a function expression in a
> thread with the subject "Static class variable creation? Options" on the
> 23rd of April 2003. My first post in that thread stated the 'accepted
> wisdom' of the day; that the only possibility for  'static' class
> members is to create them as properties of the constructor. You will
> notice that Douglas Crokford also responded to that OP, with pretty much
> the same advice.

"properties of the constructor" ?

Please have a look at what Crockford had in his site in March 2002,
more than *a*year*before* the thread you're referring to:

http://web.archive.org/web/20020605052819/www.crockford.com/javascript/private.html

<quote>
This pattern of public, private, and privileged members is possible
because JavaScript has closures. What this means is that an inner
function always has access to the vars and parameters of its outer
function, even after the outer function has returned. This is an
extremely powerful property of the language. There is no book
currently available on JavaScript programming that shows how to
exploit it. Most don't even mention it.
</quote>

> (...) So, if inline call to the function expression, used to
> achieve some notion of 'private' had occurred to Douglass Crokford
> independently of his technique for emulating private instance members in
> javascript then it really wouldn't have taken him long to put the two
> together, and so would be responding to 'static class variable' posts
> with examples of both public and private. (...)
--
Jorge.
From: Richard Cornford on
On Jun 3, 2:16 pm, Ry Nohryb wrote:
> On Jun 3, 2:30 am, Richard Cornford wrote:
>> (...)
>> I first published my use of an inline call to a function expression
>> in a thread with the subject "Static class variable creation?
>> Options" on the 23rd of April 2003. My first post in that thread
>> stated the 'accepted wisdom' of the day; that the only possibility
>> for 'static' class members is to create them as properties of the
>> constructor. You will notice that Douglas Crokford also responded
>> to that OP, with pretty much the same advice.
>
> "properties of the constructor" ?

Yes, properties of the constructor. This is in relation to emulating
Java's notion of (public) static members, and uses similar syntax to
access those members (where the constructor function's name is
substituted for the Java class name).

> Please have a look at what Crockford had in his site in March 2002,
> more than *a*year*before* the thread you're referring to:
>
> http://web.archive.org/web/20020605052819/www.crockford.com/javascrip...

I am (and was) familiar with it.

> <quote>
> This pattern of public, private, and privileged members is possible
^^^^^^^^^^^^

The pattern in question is the one for emulating private instance
members with javascript, as the example code demonstrates
(particularly the use of "Constructor" as the function name in the
examples).

> because JavaScript has closures. What this means is that an inner
> function always has access to the vars and parameters of its outer
> function, even after the outer function has returned. This is an
> extremely powerful property of the language. There is no book
> currently available on JavaScript programming that shows how to
> exploit it. Most don't even mention it.
> </quote>

Yes, so that is one application of closures to achieve an emulation of
private instance members in javascript. It provides no evidence of his
being in a position to provide a 'private static' emulation, and the
fact that he did not propose such an emulation when responding to a
thread that directly addressed the question suggest that he was not
aware of any such application of closures. Just saying 'closures are
extremely powerful' certainly does not qualify as evidence for any
particular application of them.

>> (...) So, if inline call to the function expression, used to
>> achieve some notion of 'private' had occurred to Douglass Crokford
>> independently of his technique for emulating private instance
>> members in javascript then it really wouldn't have taken him long
>> to put the two together, and so would be responding to 'static
>> class variable' posts with examples of both public and private.
>> (...)

My point being that failing to state the possibility when asked
suggest not knowing the possibility.

Richard.
From: Ry Nohryb on
On Jun 3, 4:32 pm, Richard Cornford <Rich...(a)litotes.demon.co.uk>
wrote:
> (...)
> Yes, so that is one application of closures to achieve an emulation of
> private instance members in javascript. It provides no evidence of his
> being in a position to provide a 'private static' emulation, and the
> fact that he did not propose such an emulation when responding to a
> thread that directly addressed the question suggest that he was not
> aware of any such application of closures. (...)

OK. It's time for a rewind then, ISTM.

I say: it's my understanding that you're claiming that the use of:

var Constructor= (function f () { ... })();

instead of

function f () { ... }; var Constructor= f();

is your invention ("you got the ball rolling").

If that's not it, please, tell me what is it, exactly, that you're
claiming as your invention, with an example ?
--
Jorge.