Anything beyond this and you are begging for trouble because there's always context-specific gotchas.
Anything beyond this and you are begging for trouble because there's always context-specific gotchas.
> Unfortunately, this method only works when the source object contains serializable value types and does not have any circular references. An example of a non-serializable value type is the Date object - it is printed in a non ISO-standard format and cannot be parsed back to its original value :(.
source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
I'm saying that the article is wrong when it says that JSON.stringify does not transform Dates into ISO string.
Right after that, the article says "cannot be parsed back to its original value" when it definitely can be parsed back. JSON.parse does not do it by default but that was never his point.
The broader point, which is entirely correct, is that you don't get back an exact copy of the object you want to clone, because the date fields don't end up being the same type.
let d = new Date(); let s = JSON.parse(JSON.stringify(d));
s will not be a clone of d.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
The article says it does not return a ISO string. I'm saying it does. The author as agreed with me and will update the article.