Skip to content

Commit

Permalink
CLJS-495: add exists? macro
Browse files Browse the repository at this point in the history
`exists?` can be used to determined whether some value exists. In
JavaScript this is traditionally accomplished with `typeof foo ==
'undefined'`. This allows for feature detection across heterogenous JS
clients.
  • Loading branch information
swannodette committed Apr 18, 2013
1 parent d10c702 commit 3ee148a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/clj/cljs/core.clj
Expand Up @@ -213,6 +213,9 @@
(defmacro false? [x]
(bool-expr (list 'js* "~{} === false" x)))

(defmacro exists? [x]
(bool-expr (list 'js* "typeof ~{} !== 'undefined'" x)))

(defmacro undefined? [x]
(bool-expr (list 'js* "(void 0 === ~{})" x)))

Expand Down

0 comments on commit 3ee148a

Please sign in to comment.