First of all, thanks a lot for ClojureScript. A lot of interesting new stuff
to learn and it has been very educational to read the ClojureScript source
code.
The following had me scratching my head for far too long. I translated some
quite simple code from the closure book (the one with the bird on the cover)
and I couldn’t get it to work. The problematic part of the program was the
following js function:
example.main = function() {
var root = goog.dom.getElement('root');
root.addEventListener('click', example.click, false /* capture */);
root.addEventListener('mouseover', example.mouseover, false /* capture
*/);
root.addEventListener('mouseout', example.clearHighlight, false /* capture
*/);
};
which I translated to:
(defn ^:export main []
(let [root (dom/getElement "root")]
(doto root
(.addEventListener 'click' click false)
(.addEventListener 'mouseover' mouseover false)
(.addEventListener 'mouseout' clear-highlight false))))
No compile-time errors, warnings or runtime errors. And no events fired. Can
you spot the mistake? It’s kind of a special case but I wonder if it would
be possible for the compiler to generate a warning. It’s a mistake that I
think experienced javascript developers might have a hard time to spot.
Thanks,
Jonas
(The problem, of course, is that ‘click’ is a string in javascript but
evaluates to the symbol click’ in clojurescript so it’s easy to make
copy-paste errors)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en