binaryage / cljs-oops

ClojureScript macros for convenient native Javascript object access.
Other
351 stars 13 forks source link

Escaping special symbols #15

Closed piranha closed 6 years ago

piranha commented 6 years ago

I'm using SheetJS in some project and I need to retrieve data from obj["!ref"]. Doing (oget obj "!ref") obviously warns me about punching and still generates code about it. Right now I've reverted to using aget, but still it would be nice to handle that case. :)

P.S. Hi! :)

darwin commented 6 years ago

Throw backslashes at it, don't remember details, but it should work: https://github.com/binaryage/cljs-oops/blob/f74ce8d9f7e61426912160f858e71588bdfecf75/test/src/tests/oops/main.cljs#L182-L197

piranha commented 6 years ago

Ah, two backslashes! Okay, thanks, with one backslash compiler complains.

darwin commented 6 years ago

Well, technically it is one backslash in the string. But you have to write two to get a single one in clojure/java string. If you were to read that selector string from a file or construct it progmatically you would use only one backslash.