3 ms·
They mean you can unpack lists: a, b, *rest = args So why not dicts: "a": a, "b": b, **rest = kw_args Also, in JS the destructuring does not fail becaus
by tuukkah 3y ago
They mean you can unpack lists:
a, b, *rest = args
So why not dicts:
"a": a, "b": b, **rest = kw_args
Also, in JS the destructuring does not fail because of extra elements even if you don't capture them. Further, in JS you don't need the quotes, and a: a can be shortened as simply a. You'll need the dict curly braces though. Thus the same in JS, which you see a lot e.g. for properties of a component in React code:
{ a, b } = props;
It's quite nice with no excessive "line noise" and even makes up for JS functions lacking real keyword arguments.
- BiteCode_dev 3y agoAlso JS allows you to define default values if the key is missing, and Python's pattern matching doesn't.