No, because that might not be what you want your code to do. As a JavaScript
programmer you have to understand what function scope means, and how to use
it appropriately. If "hid" is a variable that's in scope when you define an
anonymous function, your functions will refer to that specific variable. If
you define multiple anonymous functions in the same scope, they will
likewise all reference the same specific variable (and sometimes that's what
you want).  If you want each new anonymous function to have its own separate
variable named "hid", then the way you tell the compiler what you want is by
wrapping another function around the code that generates your anonymous
function, and passing "hid" in as the argument to the wrapper function.
Having the compiler try and second-guess what it thinks you *meant* would be
bad, because someday some JavaScript programmer would try to share a
variable between multiple anonymous functions, and would be scratching their
head trying to figure out why the "smart" compiler was failing to obey the
rules of JavaScript function scope.

m

On Wed, Sep 21, 2011 at 2:34 PM, Eric Harris-Braun
<zippy.314....@gmail.com>wrote:

>
> Shouldn't the clojurescript compiler detect that the usage of "hid" in
> the function in the first case requires the creation of an anonymous
> function to close around that value?  Why do I have to do it manually?
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to