Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojurescript and Google Closure: How to correctly require a namespace or import a class?

I noticed in the tut Clojurescript 101 that you can use closure classes like:

(ns async-tut1.core
  (:import [goog.net XhrIo]))

But there is a note that says:

Note: import is only for this use case, you never use it with ClojureScript libraries

What does it really mean? As I understand it, you should not import classes this way. Am I correct? If I am, how would you do it then? Many thanks.

like image 203
roboli Avatar asked May 21 '14 11:05

roboli


1 Answers

If you want to import the Closure classes, you use import, if you are importing functions or vars, then you use require or use:

(ns async-tut1.core
  (:require [goog.events :refer [listen] :as ev])
  (:import [goog.net XhrIo]))

What it means is that the import form is specific to the use case of importing classes from the host libraries (google closure modules).

like image 189
Joaquin Avatar answered Sep 20 '22 19:09

Joaquin