Graduated in Digital Media M.Sc. now developing the next generation of educational software. Since a while I develop full stack in Javascript using Meteor. Love fitness and Muay Thai after work.
This example, and the problem statement, are using a nested data structure; not functions or constructors. For the purposes outlined above this is perfectly valid.
Front end developer from Greece with professional experience in large e-commerce, administration and betting applications. Interests include: ECMAScript, Typescript, React, SEO.
This is indeed a nice trick, but do keep in mind that in order for this to work the object must not contain dates, functions, undefined, infinity, nan, regexes, maps, sets, blobs, file lists, image data, sparce / typed arrays or any other complex types. For the majority of the cases though it will do the trick.
You can also use
JSON.parse(JSON.stringify(obj))
But stringify removes lots of things so you need to write reviver etc. to support instances or constructor refrrences
This example, and the problem statement, are using a nested data structure; not functions or constructors. For the purposes outlined above this is perfectly valid.
Haha! Gary 1 Interviewer 0 😂
This is indeed a nice trick, but do keep in mind that in order for this to work the object must not contain dates, functions, undefined, infinity, nan, regexes, maps, sets, blobs, file lists, image data, sparce / typed arrays or any other complex types. For the majority of the cases though it will do the trick.
If there had been any of the above mentioned, then I would not have recommended my approach.
As you stated this works in the majority of situations and for the examples given.