The accepted answer did not work for me with the javascript object window.performance.timing . This is because Object.keys() does not actually return the details for the PerformanceTiming object.
(.keys js/Object (.-timing (.-performance js/window)) ; =>
This is despite the fact that PerformanceTiming details are really iterable using the vanilla JavaScript loop:
for (a in window.performance.timing) { console.log(a); }
The following is what I came up with to convert an arbitrary JavaScript object to a ClojureScript map. Pay attention to the use of two simple Google Closure features.
goog.typeOf wraps typeof , which is usually not available to us in ClojureScript. I use this to filter out the details that are functions.goog.object.getKeys wraps for (prop in obj) {...} , creating the result of an array that we can reduce to a map.
Decision
(defn obj->clj [obj] (-> (fn [result key] (let [v (aget obj key)] (if (= "function" (goog/typeOf v)) result (assoc result key v)))) (reduce {} (.getKeys goog/object obj))))
Aaron blenkush
source share