Вопрос

How to make LightTable show JavaScript object details inline?

Currently I'm evaluating the ClojureScript forms inside LightTable with connection to external browser using script tag. When evaluating a form, the form returns [object Object] as the evaluation result, and I want to see the content of this object.

Это было полезно?

Решение

[object Object] is the default string representation of Javascript objects. Unfortunately JS objects are much more opaque than the Clojure(script) data structures. There are several ways to improve the situation but none of them is prefect.

You can overwrite the toString() method for the object or its prototype and return a custom format. This will actually change the formatting when LightTable attempts to print the object. You change the method using standard JS interop, for example:

(set! (.-toString o) (fn [obj] "some text"))

There are all sorts of ways to inspect the object that you can use to get the formatting you want. See this question for inspiration: How to inspect Javascript Objects

Another way is to simply log the object to the console if you are developing for a browser. You will likely get a more elaborate description than the standard one, depending on which browser you are using.

(defn log [o]
    (.log js/console o))

Hope this helps!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top