Closed vshesh closed 8 years ago
Yes the behavior is as intended. It is not only dashes -
to underscores _
but far more and on (or at least what people would expect) infinitely deep objects. The performance hit would be simply too much. Keep in mind, unlike Clojure, JavaScript does allow self-reference and circular dependencies. The translation of those keys would be a nightmare, and then one would still have to translate any code using their names as well e.g. (:foo? bar)
would need to become (:isFoo bar)
. The number of symbols is also extensive:
:foo->bar
:foo+bar
:foo!
:foo?
:*foo*
:*foo
And all sorts of combinations possible. If you take a peek at the wisp backend, you'll see that for symbols alone, this already quickly becomes messy. The way it is now, keywords are just strings and that is probably for the best. To treat them as symbols or functions would be stretching it and definitely isn't currently supported.
Ok, that makes sense.
I suppose the thing to do is use (get x :y-z)
which is the correct clojure way to access an element anyway. the .
syntax is supposed to be for interop, so the fact that that compiles to camelCase to match js objects is actually the right thing.
Thanks for the explanation!
If I write a function like
it will compile to
However, if I try to call this function with
That compiles to
which is obviously not symmetrical, and returns
undefined
instead of1
.I'm curious as to whether this behavior is expected, and if so, why, or whether this is unintended (and if so, how we might fix it). It's just strange to have to have pass
f({:yZ 1})
to a function that uses:y-z
instead.