Chase Sandmann
Chase Sandmann

Reputation: 5005

Clojurescript: Create New Object from Namespace

I'm relatively new to ClojureScript and having never worked in a lisp-like language before, I must say that the documentation is rather... lacking. I just want to transform the following JavaScript statement into ClojureScript:

var obj = new namespace1.namespace2.SomeObject();

I know that you can create new instances of an object in cljs by writing something like

(SomeObject.)

but trying

(def obj (namespace1/namespace2/SomeObject.))

didn't compile. What should I be doing instead?

Upvotes: 2

Views: 1893

Answers (1)

Joaquin
Joaquin

Reputation: 2744

Have a look at this answer, it is exactly the same question:

https://stackoverflow.com/a/23653459/1400662

Pasted here:

Using js/a.b.c.d is a bad practice and is likely to break in future versions of the compiler (because it is not a clojure compatible version of interop from what I know)

The good way would be:

(def LatLng (.. js/google -maps -LatLng))

(LatLng. 100 100)

Upvotes: 4

Related Questions