4 ms·
"..." in JS is a lot like "*args" in Python, isn't it?
by captainmuon 4y ago
"..." in JS is a lot like "*args" in Python, isn't it?
- jakear 4y agoIt unifies *args and **kwargs.
- Tagbert 4y agoSupersymmetry syntax
- ludamad 4y agoI'm not sure I understand the point about kwargs. That's a feature specific to python keyword params - what's the JS equivalent with ... here?
- brundolf 4y agoThey're probably talking about the fact that it also works on objects (JS equivalent of dicts)
- jakear 4y agoYes, {**{'hello':1}, **{'world':2}} === {...{hello:1}, ...{world:2}} The name "kwargs" is unimportant, I'm referring to the ** operator itself. Edit: worth mentioning this applies in the consuming named arguments sense as well: ({arg1, arg2, ...rest}) => {}
- culi 4y agoexcept it's not just for function arguments/parameters. It can be used in all sorts of contexts to spread out an array or object. E.g. ```js const object1 = { field1: true, field2: 42 }; const object2 = { ...object1, field3: 'the meaning of life, the universe, and everything' }; ```
- valbaca 4y agobasically. They're both read as "spread"