5 ms·
> can you think of a destructuring method that operates with access by name, rather than by position? Yeah, this in JS: obj = {a: 1, b: 22, c: 333} co
by frou_dh 7y ago
> can you think of a destructuring method that operates with access by name, rather than by position?
Yeah, this in JS:
obj = {a: 1, b: 22, c: 333}
const {b, a} = obj
My original point was more that, even in languages that have both "proper" traditional tuple types and the parenthesised destructuring syntax, we're not obligated to use destructuring. i.e. writing the following is perfectly legitimate, if verbose:
a_tup = function_returning_tuple()
x = first(a_tup)
y = second(a_tup)
- hyperpallium 7y agoI hadn't seen that. It is a bit shorter, because you needn't repeat the source object. My e.g. would be lim = getLim(); const {minimum: lo, maximum: hi} = lim;