4 ms·
The syntax isn't meant for you to have to create a temporary variable in order to use it; that would be pretty pointless. It's meant for cases when you already
by RussianCow 10y ago
The syntax isn't meant for you to have to create a temporary variable in order to use it; that would be pretty pointless. It's meant for cases when you already have a variable with the same name as the key you want to set.
- bpicolo 10y agoRight. But in almost all cases I'd prefer to do away with it entirely, and not encourage extra variables for the sake of usage. It makes code more ambiguous (for anybody not coming from javascript and being used to it)
- kevindqc 10y agoHow does it encourage to use extra variables? If you have a variable with the name use it, otherwise do whatever you usually do like calling a function. It doesn't encourage doing something like const id = getId(); let obj = {id, otherProp: 'something'}; vs let obj = {id: getId(), otherProp: 'something'}; ?
- bpicolo 10y agoRight. The real argument is I don't like the additional ambiguity. For me, it doesn't seem like a particularly ergonomic syntax choice.