zcaudate
zcaudate

Reputation: 14258

In clojurescript, how would all protocols of an object be listed?

I have defined a function that lists the type

(defn js-type [o]
   (let [ty (type o)
        ty (if (and ty (.-cljs$lang$type ty))
             (.-cljs$lang$ctorStr ty)
            (js/goog.typeOf o))]
  ty))

usage

(js-type (keys {:a 1})) ;=> "cljs.core/KeySeq"

I would like to have a function in clojurescript that lists all the protocols

(js-protocols (keys {:a 1})) ;=> [Object, IMeta, IWithMeta .... INext ] 

all protocols for KeySeq are here: https://github.com/clojure/clojurescript/blob/master/src/cljs/cljs/core.cljs#L5881-L5932

Upvotes: 2

Views: 201

Answers (1)

dnolen
dnolen

Reputation: 18556

This is yet another reflection facility that does not exist at runtime. You can get this information via a macro by looking at the contents of cljs.analyzer/namespaces or through the ClojureScript analyzer/compiler directly.

Upvotes: 2

Related Questions