arohner / scriptjure

a Clojure library for generating javascript
187 stars 15 forks source link

Chainable aget #9

Closed christophermaier closed 13 years ago

christophermaier commented 13 years ago

I tweaked aget to accept multiple keys, allowing you to generate Javascript code like this:

foo[bar][baz]

using Scriptjure code like this:

(aget foo bar baz)

instead of this:

(aget (aget foo bar) baz)

It's backward compatible with the current aget behavior, so it won't break anyone's code. I added tests for this new functionality, as well as documentation in the README file.

An alternative approach might be to create a new special form: aget-in. Like clojure.core/get-in, aget-in would accept a vector of keys (as opposed to a vararg with '&'). This might be better in the long run, as it would allow you to easily create key sequences programmatically. It's also closer to Clojure's approach, which is always nice. If you like that approach better (and the idea of this patch in general), I'll make the necessary changes and resubmit.

Thanks, Chris