ECMA-262-3 in detail. Chapter 6. Closures.

  • Thread starter Dmitry A. Soshnikov
  • Start date
D

Dmitry A. Soshnikov

OK, colleagues, as I've mentioned some days ago, the translation one
of my articles is finished. I decided to start from the chapter 6 -
"Closures". The article is mostly about the general theory of closures
and from the viewpoint of this general theory, ECMAScript closures
implementation is discussed and explained. This articles is dependent
on two previous articles: chapter 4 - "Scope chain" and chapter 2 -
"Variable object" which are not translated yet (but for most regulars
of this group I guess there's no need to explain what are scope chain
and variable object, so welcome).

I'll be glad for any additions, comments and corrections (technical
and in English language mistakes).

<URL: http://dmitrysoshnikov.com/ecmascript/chapter-6-closures/>

Dmitry.
 
L

lcplben

OK, colleagues,  as I've mentioned some days ago, the translation one
of my articles is finished. I decided to start from the chapter 6 -
"Closures". The article is mostly about the general theory of closures
and from the viewpoint of this general theory, ECMAScript closures
implementation is discussed and explained. This articles is dependent
on two previous articles: chapter 4 - "Scope chain" and chapter 2 -
"Variable object" which are not translated yet (but for most regulars
of this group I guess there's no need to explain what are scope chain
and variable object, so welcome).

I'll be glad for any additions, comments and corrections (technical
and in English language mistakes).

<URL:http://dmitrysoshnikov.com/ecmascript/chapter-6-closures/>

Dmitry.

I don't do you any favors, Dmitry, by just keeping quiet, so I have to
say that this chapter is incomprehensible. Almost all the words are
real English words but some of them are near-meaningless in context;
and their arrangement is sometimes awkward. I had to stop reading at
this point:

"Actual parameter related to funarg in this case is the anonymous
function, passed to functional function.

"In turn, the function which has functional argument is called as
functional or, is closer to mathematics, as operator. In the example
above, functional has the same name — functional."

I don't mean to be mean but the mean reader might meaningfully ask,
"wtf do it mean?" For example, what does "functional function" in the
first sentence tell us? That the function you refer to actually does
something, i.e., it's "functional?" Or that the function is named
"functional?" Why introduce the notion of mathematical operator? Does
it add to my understanding? On the contrary, it's a stumbling block
and remains so for seconds while I figure out what you're trying to
say.

Whew! I want to learn about closures but learning it here it needs too
much work and time.

-- ben
 
D

Dmitry A. Soshnikov

I don't do you any favors, Dmitry, by just keeping quiet, so I have to
say that this chapter is incomprehensible. Almost all the words are
real English words but some of them are near-meaningless in context;
and their arrangement is sometimes awkward. I had to stop reading at
this point:

"Actual parameter related to funarg in this case is the anonymous
function, passed to functional function.

"In turn, the function which has functional argument is called as
functional or, is closer to mathematics, as operator. In the example
above, functional has the same name — functional."

I don't mean to be mean but the mean reader might meaningfully ask,
"wtf do it mean?" For example, what does "functional function" in the
first sentence tell us? That the function you refer to actually does
something, i.e., it's "functional?" Or that the function is named
"functional?" Why introduce the notion of mathematical operator? Does
it add to my understanding? On the contrary, it's a stumbling block
and remains so for seconds while I figure out what you're trying to
say.

Whew! I want to learn about closures but learning it here it needs too
much work and time.

Thanks for your meaning. As I also told earlier in comments for
Russian versions of this articles - this articles are mostly about
theory than about practical "easy to understand with funny pictures
copy-paste" solutions. So if some parts seems complex (and not because
of English words mistakes) I recommend to start first from practical
pragmatic articles and understand closures in general and then to go
back to theoretical articles such this one.

Regarding to what is "functional" - it's the term which is used in
function programming to name function object which has functional
argument. In the example of the articles such function has the same
name - "functional".

Dmitry.
 
L

Laser Lips

Regarding to what is "functional" - it's the term which is used in
function programming to name function object which has functional
argument. In the example of the articles such function has the same
name - "functional".

Dmitry.

Dmitry, I think lcplben understood your teaching on Closures but what
he/she is trying to point out is that because your example function
names closely match the subject matter off your discussion, the reader
could get confused and bogged down with mentally separating metaphors
from facts.

So, instead of this...

function functional(funArg) {
funArg();
}

functional(function () {
alert('funArg');
});

Use this...

function exampleFunc(funArg) {
funArg();
}

exampleFunc(function () {
alert('funArg');
});

Graham
 
D

Dmitry A. Soshnikov

Dmitry, I think lcplben understood your teaching on Closures but what
he/she is trying to point out is that because your example function
names closely match the subject matter off your discussion, the reader
could get confused and bogged down with mentally separating metaphors
from facts.

So, instead of this...

function functional(funArg) {
  funArg();

}

functional(function () {
  alert('funArg');

});

Use this...

function exampleFunc(funArg) {
  funArg();

}

exampleFunc(function () {
  alert('funArg');

});

Yep, it will be better and less confusing, thanks, will change.

Dmitry.
 
D

Dr J R Stockton

In comp.lang.javascript message <e20bacef-c35e-4c56-921e-a98423438af8@j2
7g2000yqn.googlegroups.com>, Tue, 2 Mar 2010 00:31:57, Dmitry A.
Soshnikov said:
I'll be glad for any additions, comments and corrections (technical
and in English language mistakes).

For that, you need to state whether you intend it to be in proper
English or in what Americans consider to be English. You should be
prepared to disregard anything said by those who do not explicitly
identify themselves as native speakers of one or the other, or as
Dutch/Danish/Norwegian. It is sometimes difficult to correct English
without knowing /a priori/ *exactly* what it is intended to mean; and if
the English can be corrected without knowing that, then it does not need
to be corrected unless you want to conceal being a Russian.

"As it is known," -> "As is known,"

"Actual parameter related to" -> "The actual parameter related to"

"28.02.2010" -> "2010-02-28" // ISO 8601 is unambiguous.

"2010and" !!!

"However, the described pattern is not the unique solution." If the
solution is unique, nothing else can be a solution. "is not the only"
or "is not a unique".

"I with pleasure will answer them" - acceptable, but the British would
be more likely to write "I will answer them with pleasure"

"in Ruby, the various forms of closures differently processing return in
certain cases are possible: " -? "in Ruby, various forms of closures
processing return differently are possible in certain cases: " ??

"however, in the ECMA-262-3 specification it is told nothing about it"
-> "but in standard ECMA-262-3 nothing is said about it" ?


That was just at a quick glance.

You should also not override the reader's choice of font face and size
for ordinary body text.

GC: note code layout, spaces in particular. But s/;/ ;/g ?
 
L

lcplben

Thanks for your meaning.

Ha-ha-ha! Yeah, well, de rien mon vieux :)
I recommend to start first from practical
pragmatic articles and understand closures in general and then to go
back to theoretical articles such this one.

Accepted with thanks. And I'll be looking for some of those "easy to
understand with funny pictures copy-paste" solutions to come my
way :)
Regarding to what is "functional" - it's the term which is used in
function programming to name function object which has functional
argument. In the example of the articles such function has the same
name - "functional".

Heh! There you go again! :)

Graham explained much better (and more politely) than I what I was
trying to get at. Further, with respect to function names in the text
of the article, you might consider emphasizing what those productions
are, perhaps by attaching parentheses to function names, as maybe:

"Functional" is the term we use to describe a function object which
takes as an argument a reference to another function. In my example,
the argument is a reference to "functional( )".

Disclaimer: I have no idea if the last two sentences are accurate.
Proof, if any were needed, that I could use a couple o' them copy-
paste thingies.

-- ben
 
D

Dmitry A. Soshnikov

In comp.lang.javascript message <e20bacef-c35e-4c56-921e-a98423438af8@j2
7g2000yqn.googlegroups.com>, Tue, 2 Mar 2010 00:31:57, Dmitry A.
Soshnikov <[email protected]> posted:




For that, you need to state whether you intend it to be in proper
English or in what Americans consider to be English.  You should be
prepared to disregard anything said by those who do not explicitly
identify themselves as native speakers of one or the other, or as
Dutch/Danish/Norwegian.  It is sometimes difficult to correct English
without knowing /a priori/ *exactly* what it is intended to mean; and if
the English can be corrected without knowing that, then it does not need
to be corrected unless you want to conceal being a Russian.

"As it is known,"  ->   "As is known,"

"Actual parameter related to"   ->  "The actual parameter related to"

"28.02.2010"  ->   "2010-02-28"          // ISO 8601 is unambiguous.

"2010and"  !!!

"However, the described pattern is not the unique solution."  If the
solution is unique, nothing else can be a solution.  "is not the only"
or "is not a unique".

"I with pleasure will answer them" - acceptable, but the British would
be more likely to write "I will answer them with pleasure"

"in Ruby, the various forms of closures differently processing return in
certain cases are possible: " -? "in Ruby, various forms of closures
processing return differently are possible in certain cases: " ??

"however, in the ECMA-262-3 specification it is told nothing about it"
-> "but in standard ECMA-262-3 nothing is said about it" ?

That was just at a quick glance.

You should also not override the reader's choice of font face and size
for ordinary body text.

Thanks a lot, Dr J R Stockton, this is exactly what I need; fixed all
your mentions.
GC: note code layout, spaces in particular.  But s/;/ ;/g ?

Sorry, I didn't understand about "s/;/ ;/g ?".

Thanks again.

Dmitry.
 
D

Dmitry A. Soshnikov

"Functional" is the term we use to describe a function object which
takes as an argument a reference to another function. In my example,
the argument is a reference to "functional( )".

Yeah, also could be so, but I proffered function name suggested above
by Laser Lips; already fixed. About "...*we* use to describe..." - not
we, but this is the general theory of functional programming and
mathematics in general. As I mentioned functionals, again more
generally also called as *operators*.
Disclaimer: I have no idea if the last two sentences are accurate.
Proof, if any were needed, that I could use a couple o' them copy-
paste thingies.

I don't completely understand -- you asking me to proof something to
you, right? Or what? I just informed you and explained closures from
the general theory and drew the parallel with ECMAScript; this is not
mine terminology, this is general terms. For the technical part of
closures in ECMAScript I have separate "Chapter 4. Scope chain", where
scope chain and [[Scope]] property of function object are explained in
details, but, unfortunately, it's not translated yet.

If you ask about is it true that such functions in functional
programming (and in mathematics) are called as *functionals*, well, I
can suggest to read some book about functional programming (maybe some
about Lisp, can't suggest exact book); maybe you can find it in
Wikipedia also.

P.S.: thanks again for everyone, if you help to form sentences more
correctly and is more adapted for English readers (which means, you
help to translations of article(s) in a whole), I'll include you in
section of "Credits" where will be written something like "translated
by ... with help of <You name with link to you site>".

Dmitry.
 
I

Ivan S

On Mar 3, 10:46 am, "Dmitry A. Soshnikov" <[email protected]>
wrote:

Hi Dmitry. I can understand "your" English very well, because we have
similar native languages. Leave the mistakes (I'm joking of
course.)!! :)
 
D

Dr J R Stockton

In comp.lang.javascript message <df79ad79-3b4d-4ed2-9447-8870cefa4011@y1
7g2000yqd.googlegroups.com>, Wed, 3 Mar 2010 01:46:30, Dmitry A.
Soshnikov said:
Sorry, I didn't understand about "s/;/ ;/g ?".

It is, I think, the way TL would write "replace ';' by ' ;'"; i.e. I
think that it is nicer to put a space before a semicolon. And "GC"
should have been "GS".
 
D

Dmitry A. Soshnikov

In comp.lang.javascript message <df79ad79-3b4d-4ed2-9447-8870cefa4011@y1
7g2000yqd.googlegroups.com>, Wed, 3 Mar 2010 01:46:30, Dmitry A.
Soshnikov <[email protected]> posted:





It is, I think, the way TL would write "replace ';' by ' ;'"; i.e. I
think that it is nicer to put a space before a semicolon.  And "GC"
should have been "GS".

I'm not sure about this. Is it so in English grammar? In Russian
grammar there's no space before any punctuation sign (except dash
which has surrounding spaces).

So,

"hello!", but not "hello !"
"then, there" but not "then , there"
"go; ride;" but not "go ; ride ;"

Dmitry.
 
D

Dmitry A. Soshnikov

On Mar 3, 10:46 am, "Dmitry A. Soshnikov" <[email protected]>
wrote:

Hi Dmitry. I can understand "your" English very well, because we have
similar native languages. Leave the mistakes (I'm joking of
course.)!! :)

Hi Ivan, that's great! ;) So, if you know English very well, you can
help also.

Dmitry.
 
T

Thomas 'PointedEars' Lahn

Dr said:
Dmitry A. Soshnikov posted:
Sorry, I didn't understand about "s/;/ ;/g ?".

It is, I think, the way TL would write "replace ';' by ' ;'"; [...]
^^
You are quite obsessed with me, yes? s/x/y/ is simply yet another example
of hacker jargon, for goodness' sake, so common on Usenet and other
convergence points of the community that it went into several jargon files
already. And obviously some people just don't qualify.


PointedEars
 
D

Dmitry A. Soshnikov

Dr said:
Dmitry A. Soshnikov posted:
It is, I think, the way TL would write "replace ';' by ' ;'"; [...]

                          ^^
You are quite obsessed with me, yes?  s/x/y/ is simply yet another example
of hacker jargon, for goodness' sake, so common on Usenet and other
convergence points of the community that it went into several jargon files
already.  And obviously some people just don't qualify.

Thanks, I understand that this is a kind of jargon (hacker? :)), which
I always try to avoid especially in articles as it can be looked not
seriously.

Dmitry.
 
I

Ivan S

Hi Ivan, that's great! ;) So, if you know English very well, you can helpalso.

Well, I don't know it very well, but I can understand it. I know what
you want to say because you try to say things in English by
translating them from your native language (which is similar to mine)
but that's a bad practice because those grammars are different. Try to
think in English terms, not your own.

I'll help you with translations if I can (but I have to say, my
English is just OK). :)

Let's start with this:
... I always try to avoid especially in articles as it can be looked not seriously.


.... I always try to avoid especially in articles because it can't look
seriously.


:)
 
D

Dmitry A. Soshnikov

Well, I don't know it very well, but I can understand it. I know what
you want to say because you try to say things in English by
translating them from your native language (which is similar to mine)
but that's a bad practice because those grammars are different. Try to
think in English terms, not your own.

I'll help you with translations if I can (but I have to say, my
English is just OK). :)

Let's start with this:


... I always try to avoid especially in articles because it can't look
seriously.

:)

Yeah, I know that, one should have a big practice to start thinking on
English; anyway, who wants to understand me, usually has no probs with
it, but only speaking English and English in articles - are different
things, mistakes in the last are not acceptable if it's your _native_
language.

Ok, are there any thoughts/additions/corrections about the technical
topic exactly?

Dmitry.
 
A

Asen Bozhilov

Ivan said:
I can understand "your" English very well, because we have
similar native languages. Leave the mistakes (I'm joking of
course.)!! :)

He isn't professional translator. He is a developer. I'm not going to
defend grammar mistakes. I do it everyday, but of course i'm working
about my English. The grammar mistakes are certainly bad, especially
when readers native langugae is English. But case with that article is
different. The original article is writen on Russian and presented
version here is translation by Dmitry on English. I prefer to read
articles with grammar mistakes instead of technical mistakes. So from
this point of view, the article of Dmitry is good and useful for
people, which wants to improve theirs knowleadge in ES.
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top