ClojureScript

New undefined? macro that safely handles undeclared variables

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

The current `undefined?` function will blow up with a JavaScript reference error if you pass it an undeclared variable.

It'd be nice to have a way to test if a JavaScript variable has been declared.
My use case is writing a ClojureScript library that extends cljs protocols to JavaScript things.
I'd like to write

(when-not (undefined? js/jQuery)

...)

to extend-type jQuery when jQuery is around.

Activity

Hide
David Nolen added a comment -

What about bound? as a name for this macro?

Show
David Nolen added a comment - What about bound? as a name for this macro?
Hide
Kevin Lynagh added a comment -

Yeah, `bound?` sounds like an appropriate name to me.

Show
Kevin Lynagh added a comment - Yeah, `bound?` sounds like an appropriate name to me.
Hide
David Nolen added a comment -

Stuart Sierra pointed out that `bound?` may have too many connotations already in Clojure. Maybe `exists?`?

Show
David Nolen added a comment - Stuart Sierra pointed out that `bound?` may have too many connotations already in Clojure. Maybe `exists?`?

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: