Hmm for some reason I recall this doesn't work consistently in all browsers. Might be wrong.
On Sunday, May 20, 2012, Moritz Ulrich wrote: > > Found a more or less nice solution: > > --8<---------------cut here---------------start------------->8--- > (defn log [& more] > (.apply (.-log js/console) js/console > (into-array (map #(if (satisfies? cljs.core.ISeqable %) > (pr-str %) > %) > more)))) > --8<---------------cut here---------------end--------------->8--- > > This prints all seqable objects using pr-str, all other objects are > passed directly to console.log. This way html elements are printed > clickable and most clojure data structures are printed in their native > representation. > > > David Nolen <dnolen.li...@gmail.com <javascript:;>> writes: > > > I didn't think that console.log.apply worked. > > > > On Sunday, May 20, 2012, Moritz Ulrich wrote: > > > >> > >> Hello, > >> > >> I want to write a simple logging-wrapper around console.log, with the > >> background of being able to enable/disable logging at any time. This is > >> my current implementation: > >> > >> --8<---------------cut here---------------start------------->8--- > >> (defn log [& more] > >> (.log js/console (apply pr-str more))) > >> --8<---------------cut here---------------end--------------->8--- > >> > >> This particuliar implementation is pretty nice (and awfully slow) for > >> Clojure data structures. It's unusablw for raw javascript data like > >> HTMLElements and other Objects with no reasonable implementation of > >> pr-str. > >> > >> I want to print "raw" javascript objects using console.log and clojure > >> data using pr-str. > >> > >> Doing this sort of switch should be easy, where I'm stuck is running > >> apply on console.log. I want to do something like: > >> > >> --8<---------------cut here---------------start------------->8--- > >> (apply (.-log js/console) (map ... args)) > >> --8<---------------cut here---------------end--------------->8--- > >> > >> Which doesn't work. (I guess because console.log doesn't feature .call) > >> > >> Can anyone point me in the right direction? > >> > >> > >> Cheers, > >> > >> -- > >> Moritz Ulrich > >> > >> -- > >> 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<javascript:;> > <javascript:;> > >> 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 <javascript:;> <javascript:;> > >> For more options, visit this group at > >> http://groups.google.com/group/clojure?hl=en > > -- > Moritz Ulrich > > -- > 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<javascript:;> > 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 <javascript:;> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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