Hi everyone,
This is almost purely a syntactic sugar proposal, and if there's already a
proposal like this being/been discussed, please point me that way, I
couldn't find anything. Anyway, the use case is as follows:
You have keys that come, for example from a config file or are defined as
constants, and you want to create objects with those keys. What you
currently have to do is to use a mix of object notation syntax and
assignment:
myObject = {
someKey: 'someValue'
};
myObject[MY_KEY_ID] = 'my value';
This is usually ok, but it's a bit confusing to read especially if the
object is long and you try to find the definition inside the brackets but
can't. Also, as far as I know, `"someKey"` and `MY_KEY_ID` end up being
defined differently; I doubt that the latter matters much, but what I have
in mind would fix both things:
myObject = {
someKey: 'someValue',
[MY_KEY_ID]: 'my value'
};
So basically you could use brackets to signify that the key is the value of
an expression inside the brackets.
Cheers,
Jussi
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss