Skip to content

Instantly share code, notes, and snippets.

@cemerick
Created August 25, 2013 03:01
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cemerick/6331727 to your computer and use it in GitHub Desktop.
Save cemerick/6331727 to your computer and use it in GitHub Desktop.
`defonce` for ClojureScript
(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