I have seen in this question the following code:
obj = JSON.decode(JSON.encode(o));
What does it represent? I see that JSON.encode
and JSON.decode
are undefined.
Is this just a pseudocode or JSON
object is extended adding these functions?
I have seen in this question the following code:
obj = JSON.decode(JSON.encode(o));
What does it represent? I see that JSON.encode
and JSON.decode
are undefined.
Is this just a pseudocode or JSON
object is extended adding these functions?
Those methods are specific to the MooTools library. If you scroll further down you will see the response that should properly work in all browsers without external libraries (the downside being that it will not stringify functions):
var obj = JSON.parse(JSON.stringify(o));
The point of the code is to create a deep copy of o
.