In ClojureScript I'm trying to convert (not recursively, only the lowest level) of the global window object into a hashmap.
Usually, if js-objects are not constructed by Object, the following interop helps:
(defn jsx->clj [js-o]
(reduce (fn [m v]
(assoc m (keyword v) (aget js-o v)))
{} (.keys js/Object js-o)))
However, if I apply this to js/window I'm getting errors:
#object[TypeError TypeError: Cannot convert a Symbol value to a string]
[...]
Has anyone made experiences with this?
The mysterious error is not in your code but happens when the repl attempts to output the result.
Evaluate js/cljs
in the repl to replicate, as this is the culprit.(def foo (doall (jsx->clj js/window)))
works without a hitch except now the error appears if you evaluate (pr foo)
in the repl or just foo
by itself.