We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
yes, you're right!
I think old documentation was informing about using aget for object, but now it's changed and it's depreciated to use aget for object.
Thanks for pointing this out!
More info here:
https://github.com/cljs/api...
https://github.com/cljs/api...
There are still demos of aget/aset to access object's field, maybe update?
Thank You for this article! I also had a problem with comprehension of cljs-js interop. And by time I've got the pattern, but now my comprehension is 10 levels up :D
Thank You!
As usual I'm glad that I was able to help you! Thank you for your comment. Cheers :D
Very useful reference, thanks! A note on using goog-define and :closure-defines to parameterize builds (or some alternative to it) would be interesting.
(def js-object #js {:a 1 :b #js [1 2 3] :c #js ["d" true :e nil]})
this code is doesnt works for me
in this case in #js ["d" true :e nill] we need #js {"d" true :e nill} helps me to interop in nicely js object.
I have a feeling that there were same changes how #js and clj->js work. I need to investigate this.
Got a problem, how is `a["b"](c)` written here? I used to write `.b a c` but it will be broken after advanced compilation.
To be able to safely use (.b a c) notation you need to use :externs setting in project.clj file. Please look at "Using external JavaScript libraries" section of my article.
Got a Chinese translation!
中文翻译 http://segmentfault.com/a/1...
By the way a typo: "that invokes PolarArea function form the Chart object"
"f O R m" should be "from".
It should be fixed. Thanks for pointing this.
thanks for the tutorial. It is really help. But in your example, (def js-object (clj->js :a 1 :b [1 2 3] :c #{"d" true :e nil})), should be (def js-object (clj->js {:a 1 :b [1 2 3] :c #{"d" true :e nil}}))
You can pass list of key value pairs to `clj->js` and it works, so my example should work
Personally I'd found that pasting Qi Mi's example into a repl worked, whereas the article's example throws the following:
WARNING: Wrong number of args (6) passed to cljs.core/clj->js at line 1 <cljs repl="">
Thanks for the article though, it came in really handy! :)
Hmm, I've checked this and you and Qi are right! Sorry, for confusion. I will fix it in my text.
This is really a fantastic cheat tutorial that I'm using a bunch. Thanks!
Very nice! Thanks.
Excellent! Comprehensive and friendly to read.
Great post! How do i write the following in CLJS:
var a = "Empty spaces - what are we living for? \
Abandoned places - I guess we know the score... \
On and on! \
Does anybody know what we are looking for?";
alert(a);
...?
Thanks!
To show a message box you can use something like this:
(js/alert "some text")
how to declare a event handler in clojurescript. like $('a.page-scroll').bind('click', function(event) { alert ($(this).attr('href'));} especially the $(this)
I don't know any other option then usage of: (js* "this") - but it's ugly.
I would recommend you to use *jayq* https://github.com/ibdknox/... library - it's ClojureScript wrapper for jQuery
Currently working my way through this introduction - http://www.niwi.be/cljs-wor... - and this was ideal for demistifying some of the syntax used, thanks
I'm glad that I could help.
Btw. nice tutorial
I was looking for a comprehensible explanation of the common constructs widely used in various cljs-related tutorials (like the swanodette's one on om) and found it here. So, as all the others I send you tons of thanks for this deep and very informative post!
I'm glad that you like it. Thank you for kind words.
This is exactly what I've been looking for!
I am new to ClojureScript (and Clojure) and I am wondering how can I preview JS-generated code?
PS I've found this post only because I was looking for something related to ClojureScript in Wrocław!
Thanks, I'm glad that you like it - as I wrote before I have a plan to add part 2, but currently I can't find time to do it.
You can preview generated JS code by inspecting .js file generated from .cljs files (remember to use
:optimizations :whitespace switch)
i.e. if you compile ClojureScript form command line:
./bin/cljsc hello.cljs '{:optimizations :whitespace}' > hello.js
look at hello.js file
P.S. I would also be interested in something related Clojure/ClojureScript in Wroclaw.
Great thoughtful post.
Thanks!
Thanks for the very useful post.
You've given a nice and quick overview for those who need to refer to js-cljs interop information with detailed examples.
The js* function was something I did not know of, but certainly looks like a useful fallback when you are stuck. Although I'm sure it's not going to be recommended by the masters.
While you've linked to Luke VanderHart's blog which is very appropriate for the advanced stuff, a simple example using the ^:export tag would make your post complete, IMHO.
Thanks!
Thank you for you feedback. I agree that some info about ^:export and externs.js would improve this post - I will try to add this info in a week or two.
You should not use `aget` and `aset` to deal with objects. Those functions are meant to be used with Arrays only, for object access the recommended functions are `goog.object/get` and `goog.object/set` respectively.