Restricted Deep Copy Implementations
Learn about two methods to implement deep copy and their limitations.
We'll cover the following...
We'll cover the following...
JSON methods
There is a very easy implementation for making deep copies of JavaScript objects. Convert the JavaScript object into a JSON string, then convert it back into a JavaScript object.
Restrictions:
-
Object
ohas to be finite; otherwise,JSON.stringifythrows an error. -
The
JSON.stringifyconversion has to be lossless. Therefore, methods not allowed as members of typefunctionare ignored by the JSON stringifier. Theundefinedvalue is not allowed either. Object ...