js/String

Note:

(identical? js/String (type "”)) => true

Here is an example in a REPL:

cljs.user=> (defmulti position (fn [element x y z] (type element)))
#'cljs.user/position
cljs.user=> (defmethod position js/String [element x y z] z)
#object[cljs.core.MultiFn]
cljs.user=> (defmethod position js/Number [element x y z] x)
#object[cljs.core.MultiFn]
cljs.user=> (position "a" 1 2 3)
3
cljs.user=> (position 42 1 2 3)
1

> On Jan 10, 2016, at 9:41 PM, Sonny To <[email protected]> wrote:
> 
> I am trying to use a multi-method that dispatches base on the result returned 
> by (type)
> 
> 
> (defonce str-type (type "a"))
> 
> (defmulti position #(type %))
> 
> (defmethod position str-type [element x y z]
>  z)
> 
> (position "abc" 1 2 3)
> 
> This works but I'd like to use a literal representation of the type of a 
> javscript string instead of using (type "a")
> 
> (type "a") returns 
> #object[String "function String() { [native code] }"]
> 
> but using that in the dispatch value gives a syntax error
> 
> (defmethod position #object[String "function String() { [native code] }"] 
> [element x y z]
>  z)
> 
> The above does not work
> 
> -- 
> 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 https://groups.google.com/group/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 https://groups.google.com/group/clojurescript.

Reply via email to