I am currently learning clojure and I am trying to translate some javascript from CodeCombat to clojure/clojurescript.
var base = this;
var items = base.getItems();
if (base.built.length === 0)
base.build('peasant');
I am trying to convert the Javascript code to Clojure, but unfortunately CodeCombat doesn't give me any error message.
(def base this)
(def items (.getItems (base) ))
(def built-len ((.length) (.built (base)) ))
(if (= built-len 0)
((.build "peasant") (base) )))
Do you see any obvious mistake? I mostly followed the offical interop tutorial http://clojure.org/java_interop
asked May 20, 2014 at 20:31
Maik Klein
16.3k29 gold badges113 silver badges210 bronze badges
1 Answer 1
Use this-as macro ! However, using def is not nice inside macro... it's preferred to use let if possible!
(this-as t
(let [item (.getItems t)]
In your code remove parenthesis around base, (it's function call, and you don't want to call it).
user8472
3,3464 gold badges38 silver badges65 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
thisfrom ClojureScript stackoverflow.com/questions/15531261/…(defn get-url [path] (.getURL js/chrome.extension path))