On Friday, March 20, 2015 at 11:27:10 AM UTC-7, Charles-P. Clermont wrote:
> Hi,
> 
> I'm not sure if this is a bug or a hole in my knowledge. 
> Can someone explain why I can do 
> 
> ```
> ((.-cos js/Math) 0) ;; => 1
> ```
> 
> But not
> ```
> ((.-log js/console) "hi") ;; => Illegal Invocation 
> ``` 
> 
> The goal being to declare 
> 
> ```
> (def log (.-log js/console))
> (def cos (.-cos js/Math)) 
> ;; etc.
> ```
> 
> Thanks!
> 
> CP

You should never alias console.log like this anyway. Even if you wrap log in a 
function, you'll end up with incorrect line numbers when trying to debug 
something. For example

(defn log [& xs]
  (.apply (.-log js/console) js/console (to-array xs)))

(dotimes [x 10]
  (log x))

Will report that the log came from the *second* line in this code instead of 
where it actually appears (in the dotimes). This is bad for debugging. Just 
don't do it. Shodan had this problem originally but now uses macros to avoid it.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to