Closed STRd6 closed 13 years ago
Related: #786
closing as duplicate of #786
What was the reasoning behind the close? To me it seems like a bug, or at least an inconsistency.
Maybe you should ask @jashkenas in #786. I remember that we decided to remove dynamic keys, but not why. And it wasn't explained/linked in the commit.
I asked ages ago in #786 but he hasn't replied.
I guess this is "just one of those things".
Sorry for being tardy -- if I remember correctly, it was because some of our other language features depend on having the key known at compile time. For example, method overrides and super calls in executable class bodies. We want to know the name of the key so that a proper super call can be constructed.
Also, it makes it so that you have to closure-wrap objects when used as expressions (the common case) whenever you have a dynamic key.
Finally, there's already a good syntax for dynamic keys in JavaScript which is explicit about what you're doing: obj[key] = value
.
There's something nice about having the {key: value, key: value}
form be restricted to "pure" identifiers as keys.
Thanks for the response, it's well reasoned, and I can support it.
Thank you for clarifying this for us @jashkenas. I've made a note of this in the original ticket.
FYI:
For example, method overrides and super calls in executable class bodies. We want to know the name of the key so that a proper super call can be constructed.
True, but orthogonal to this issue.
$ coffee -bpe 'A::x = -> super'
A.prototype.x = function() {
return A.__super__.x.apply(this, arguments);
};
$ coffee -bpe 'A::[x] = -> super'
SyntaxError: cannot call super on an anonymous function.
it makes it so that you have to closure-wrap objects when used as expressions (the common case) whenever you have a dynamic key
Wrong. You never need to IIFE-wrap them since objects are always expressions.
@satyr: the dynakey proposal isn't looking good. Good riddance, I didn't like it at all.
I know this has been closed and I'm sure no one would like to comment on or answer this but I am going to point something out that relates to coffeescript and store.js:
It would be super helpful to be able to do string interpolation for store.js ... I can't reference values from a comprehension to add to the key making it impossible to save now.
do_something = for num in [5...1] store.set('user,{ name#{num}: value#{num}) })
store.js README: https://github.com/marcuswestin/store.js/#readme
@wackfordjf3 Not sure I read correctly your code, but you should re-read the linked ticket
The following code:
Gives the following error:
I would expect to be able to interpolate string keys of object literals.