Even better: with this approach, you can choose to merge elements into an pre-existing object which can help with keeping object references and reduces the need for the engine to garbage collect short-lived objects.
I get that, but just because you can do something more painfully doesn't mean that it can't be done simpler. On top of that, there is no assignment of the weapon key.
I think it can be argued that { ...hero, weapon: "sword"} is easier to read than Object.assign({}, hero, {weapon:"sword")
yes I agree that spread is easier to read than Object.assign().. so are you saying that it doesn't have to be as painful as looping through the keys but rather Object.assign is there and if you want to improve on that use spread syntax?
I don't think your NO spread for objects is right, I would likely do it like
I was thinking exactly this.
Even better: with this approach, you can choose to merge elements into an pre-existing object which can help with keeping object references and reduces the need for the engine to garbage collect short-lived objects.
Feels like a better approach!
hi Mike, are you saying this code should use Object.assign()?
Because my point was to showcase how painful it can be without spread? Help me understand, thanks :)
I get that, but just because you can do something more painfully doesn't mean that it can't be done simpler. On top of that, there is no assignment of the weapon key.
I think it can be argued that
{ ...hero, weapon: "sword"}
is easier to read thanObject.assign({}, hero, {weapon:"sword")
yes I agree that spread is easier to read than Object.assign().. so are you saying that it doesn't have to be as painful as looping through the keys but rather Object.assign is there and if you want to improve on that use spread syntax?
I think that is fair to say. Since prior to browser support that was what the transpilers often did for you.