On Tuesday, November 25, 2014 11:51:27 AM UTC-6, Brendan Younger wrote:
> Now, if only there was documentation mentioning satisfies? and explaining the 
> difference between interfaces/protocols in ClojureScript...


instance? is a Clojure(Script) host interop form that checks the class 
hierarchy of an object using the semantics of the underlying platform. E.g., in 
Java, instance? means "is this an instance of some class or interface or one of 
their parents?". In javascript it means "is this constructor's prototype in the 
object's prototype chain?". In both languages (instance? klass obj) is the same 
as "obj instanceof klass".

Protocols are a native Clojure(Script) concept and are not provided by the 
underlying platform. satisfies? tests that a protocol is implemented for some 
instance's type (directly or indirectly).

In Clojure, there are interfaces (a Java concept) and protocols (a Clojure 
concept). Most of Clojure's core "interfaces" are true *java interfaces*, not 
*protocols*. So you *cannot* say (satisfies? clojure.lang.IRef x) (you will get 
a null pointer exception). You *must* say (instance? clojure.lang.IRef x)

In ClojureScript, however, all Clojure core interfaces are *protocols*.
You *must* say (satisfies? IWatchable x). (instance? cljs.core.IWatchable x) 
will not work.

The Google Closure Compiler has a thing it calls "interfaces" for compile-time 
typechecking, but it is not available at runtime and not used by ClojureScript. 
There is nothing like a Java interface in Javascript or ClojureScript.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to