ClojureScript "console.log"

6,099 views
Skip to first unread message

Thomas Heller

unread,
Feb 4, 2012, 2:14:09 PM2/4/12
to Clojure
Hey,

I'm playing with ClojureScript and one thing that would help me out in
a big way would be to print out data at certain points.

I can call (.log js/console "test" 1 2 3 4) and it prints the expected
results, but whenever I want to log a Clojure Object I just get its
classname and can inspect how its represented in JS, interesting but
not what I need.

Is there any function I can call which outputs the data as it would
look in the code?

(.log js/console [1 2 3 4]) should log [1 2 3 4] but currently logs
cljs.core.Vector (Chrome btw.)
(.log js/console {:hello "world"}) logs cljs.core.ObjMap, etc

Basically whatever the REPL would print, I'd like to see.

(print [:a 1 "2"]) just complains with "No *print-fn* fn set for
evaluation environment".

Any hints?

Thanks,
/thomas

Stuart Sierra

unread,
Feb 4, 2012, 9:05:10 PM2/4/12
to clo...@googlegroups.com
There's a G.Closure library function -- goog.debug.expose -- that generates a string representation of a JavaScript object.

http://closure-library.googlecode.com/svn/docs/closure_goog_debug_debug.js.html

-S

David Nolen

unread,
Feb 4, 2012, 9:24:43 PM2/4/12
to clo...@googlegroups.com
pr-str is probably what you want

(.log js/console (pr-str [1 2 3 4]))

David

 
Reply all
Reply to author
Forward
0 new messages