Re: Function return function???
"RobG" <rgqld@iinet.ne t.auau> wrote in message
news:VRvTd.29$Z n.3374@news.opt us.net.au...[color=blue]
> Jarmo wrote:
> [...][color=green]
> > I've yet to see a compelling need for closures in JavaScript but I'm[/color][/color]
open to[color=blue][color=green]
> > suggestion. Bring it on ;-)
> >
> > Personally, I'd have preferred them to have designed variable scoping
> > correctly and at least provided an option for strong types then I'd have[/color][/color]
a[color=blue][color=green]
> > lot more enthusiasm for the more esoteric features.[/color]
>
> I'm a newbie to JavaScript, but find it a fascinating language.
> Your request for a compelling reason for closures and subsequent
> comment on scoping and types can be take two ways:
>
> 1. There is no need to have closures or similar functionality[/color]
Right, I've not seen an argument for closures being necessary, or where the
advantages far outweigh the disadvantages. But I'm open to such an
argument. Clearly they're not strictly necessary because they're not in C
and you can do anything with C.
[color=blue]
> 2. There are other (presumably better) ways to achieve the same
> functionality[/color]
Depends how you define 'better' but transparency, ease of writing,
understanding, and maintenance fall high on my list. Programming is not
typically, outside of academia, a solo endeavor.
[color=blue]
> I certainly can't comment on the second point, but an argument
> for the first is where you want to call a function using say
> setInterval and want to pass a lot of parameters. You can
> create an "outer" function that does all the setup work and
> creates any required variables, then use setInterval to call an
> "internal" function that uses the variables.
>
> The internal function has access to all the variables created in
> the outer function, but you haven't needed to pass them and
> their cope does not need to be global. You can keep the
> internal processing tight and fast 'cos all the heavy work was
> done beforehand.[/color]
Right, I can see situations in which one *could* make use of closures but
none in which it's necessary, and none in which I would choose to use them.
I'll try my hardest to get a closure into my next project but I can
virtually guarantee you that it'll get kicked into touch ;-) during the peer
review process.
[color=blue]
>
> --
> Rob[/color]
"RobG" <rgqld@iinet.ne t.auau> wrote in message
news:VRvTd.29$Z n.3374@news.opt us.net.au...[color=blue]
> Jarmo wrote:
> [...][color=green]
> > I've yet to see a compelling need for closures in JavaScript but I'm[/color][/color]
open to[color=blue][color=green]
> > suggestion. Bring it on ;-)
> >
> > Personally, I'd have preferred them to have designed variable scoping
> > correctly and at least provided an option for strong types then I'd have[/color][/color]
a[color=blue][color=green]
> > lot more enthusiasm for the more esoteric features.[/color]
>
> I'm a newbie to JavaScript, but find it a fascinating language.
> Your request for a compelling reason for closures and subsequent
> comment on scoping and types can be take two ways:
>
> 1. There is no need to have closures or similar functionality[/color]
Right, I've not seen an argument for closures being necessary, or where the
advantages far outweigh the disadvantages. But I'm open to such an
argument. Clearly they're not strictly necessary because they're not in C
and you can do anything with C.
[color=blue]
> 2. There are other (presumably better) ways to achieve the same
> functionality[/color]
Depends how you define 'better' but transparency, ease of writing,
understanding, and maintenance fall high on my list. Programming is not
typically, outside of academia, a solo endeavor.
[color=blue]
> I certainly can't comment on the second point, but an argument
> for the first is where you want to call a function using say
> setInterval and want to pass a lot of parameters. You can
> create an "outer" function that does all the setup work and
> creates any required variables, then use setInterval to call an
> "internal" function that uses the variables.
>
> The internal function has access to all the variables created in
> the outer function, but you haven't needed to pass them and
> their cope does not need to be global. You can keep the
> internal processing tight and fast 'cos all the heavy work was
> done beforehand.[/color]
Right, I can see situations in which one *could* make use of closures but
none in which it's necessary, and none in which I would choose to use them.
I'll try my hardest to get a closure into my next project but I can
virtually guarantee you that it'll get kicked into touch ;-) during the peer
review process.
[color=blue]
>
> --
> Rob[/color]
Comment