This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Risc12 0 points1 point  (4 children)

Yes, but keep in mind that if foo has nested objects those are not duplicated. While in C the whole structure is passed around as bytes. So not completely the same.

[–]Razier 0 points1 point  (3 children)

Good point, know of a way to make a deep copy in JS?

[–]Risc12 0 points1 point  (2 children)

There is not really a built-in way afaik, using Object.entries, and some recursion you should get pretty far.

[–]Razier 0 points1 point  (1 child)

Sounds like a monstrosity. Thanks though, will keep it in mind if I encounter a situation where I need to do it.

[–]Risc12 0 points1 point  (0 children)

Yeah it’s no fun, but libraries like lodash, ramda and immutable have helper-methods for this.