3

I am trying to convert the following line to Cljs,

var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { enableHighAccuracy:  true });

What would be the corresponding map for,

{ enableHighAccuracy:  true }

in ClojureScript? Is enableHighAccuracy a symbol?

1 Answer 1

4

If you're using interop with a library (such as geolocation, in your case), and it expects a JavaScript object, you'll need to pass it a standard JavaScript object, not a Clojure map.

You can construct one of these in ClojureScript by using the js-obj function with no arguments. This will return an empty JavaScript with no fields; you can then add fields using the aset function.

So your code would be something like:

(let [arg (js-obj)]
  (aset arg "enableHighAccuracy" true)
  (.watchPosition (.geolocation navigator) on-success on-error arg))

If this is something you find yourself doing a lot, it's easy to write a utility function to convert a ClojureScript map into a JavaScript object using whatever defaults you like; an example of such a function can be found in this gist; https://gist.github.com/1658431

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.