Re:A little bit of plain JavaScript can do a lot
by ryanbrunner on Sunday June 21, 2020 @08:17AM
(#23591607)
Neat solution - out of curiosity though, why remove the properties from the passed options? If I called that function, I wouldn't normally expect it to mutate my arguments like that.
[ Parent
| on HN ]
Re:A little bit of plain JavaScript can do a lot
by hombre_fatal on Sunday June 21, 2020 @08:41AM
(#23591705)
At a glance, they do it so that at the end they can merge in any remaining props they didn't handle after all their work building `elem` is done.
This can be accomplished non-destructively with destructuring.
const {
attributes,
classList,
style,
...rest
} = p
// elem = ...consume attributes, classList, style...
return Object.assign(elem, rest)