2

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?

Community
  • 1
  • 1
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474

1 Answers1

3

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.

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536