Created
August 25, 2013 03:01
-
-
Save cemerick/6331727 to your computer and use it in GitHub Desktop.
`defonce` for ClojureScript
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
(ns whatever.cljs | |
(:require [cljs.compiler :refer (munge)]) | |
(:refer-clojure :exclude (munge defonce))) | |
(defmacro defonce | |
[vname expr] | |
(let [ns (-> &env :ns :name name munge) | |
mname (munge (str vname))] | |
`(when-not (.hasOwnProperty ~(symbol "js" ns) ~mname) | |
(def ~vname ~expr)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/clojure/clojurescript/blob/5bc4f957ad98a6d4cd2de0576e5221e9b33bcdaf/src/clj/cljs/core.clj#L65-L67