Update - July 4, 2017
The original post is now outdated. Instead use
Example from the cljs api:
The rest of this post is now outdated
Konrad Garus has a good post explaining the details of accessing js properties from cljs. It’s worth your time to read the entire post, but here are some general guidelines.
.-property for cljs
In the normal case, you’ll want to use
.-property to access js properties. In the line-reader example, we use
.-_lastLineData to get/set data on
.-property allows the compiler to rename the property during advanced compilation, e.g.
_lastLineData could be renamed
(.-property object) is the idiomatic way to access js properties.
(aget object "property") for js
If you want your code to be accessible in js, use
aset with strings referring to the property.
Don’t mix accessors
If you sometimes use
(.-property object) and other times use
(aget object "property"), you’ll run into confusing bugs when it comes time to ship. There are few things as frustrating as bugs that only show up in prod (where you’re using advanced compilation). Be consistent, and you’ll save yourself unnecessary headaches.
Find this post useful? Share the love! Tweet