4 ms·
OK, some stuff is nice (async), but seems like the standard keeps adding syntactic sugar while not addressing more pressing daily challenges, i.e. deep cloning
by pragueexpat 10y ago
OK, some stuff is nice (async), but seems like the standard keeps adding syntactic sugar while not addressing more pressing daily challenges, i.e. deep cloning (Object.assign does not go deep).
- WorldMaker 10y agoIt's a hack, but `JSON.parse(JSON.stringify(obj))` is a relatively performant deep clone. Very few languages that I know have deep cloning outside of some sort of serialization hack anyway (C#'s deep cloning is a reuse of/leftover from binary marshalling), so this is roughly par for the course, so far as I'm aware.
- paulddraper 10y ago> is a relatively performant deep clone Relatively short, but IMO not relatively performant. All the JSON encoding/decoding takes its toll.
- WorldMaker 10y agoRelative to most purpose built deep clone libraries I've tried and most manual deep clones I've seen tried that use some combination of DFS and Object.assign. Obviously YMMV, and your performance needs likely differ from my own. (Personally, at this point I try to use immutability [with ImmutableJS or friends] over deep cloning, but sometimes a deep clone is still handy.)