Created
January 22, 2012 19:43
-
-
Save semperos/1658431 to your computer and use it in GitHub Desktop.
ClojureScript to JavaScript (from mmcgrana)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn clj->js | |
"Recursively transforms ClojureScript maps into Javascript objects, | |
other ClojureScript colls into JavaScript arrays, and ClojureScript | |
keywords into JavaScript strings." | |
[x] | |
(cond | |
(string? x) x | |
(keyword? x) (name x) | |
(map? x) (.strobj (reduce (fn [m [k v]] | |
(assoc m (clj->js k) (clj->js v))) {} x)) | |
(coll? x) (apply array (map clj->js x)) | |
:else x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn clj->js | |
"Recursively transforms ClojureScript maps into Javascript objects, | |
other ClojureScript colls into JavaScript arrays, and ClojureScript | |
keywords into JavaScript strings." | |
[x] | |
(cond | |
(string? x) x | |
(keyword? x) (name x) | |
(map? x) (.-strobj (reduce (fn [m [k v]] | |
(assoc m (clj->js k) (clj->js v))) {} x)) | |
(coll? x) (apply array (map clj->js x)) | |
:else x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment