if you need to read or clone all of a model’s data attributes, use its toJSON() method. This method returns a copy of the attributes as an object (not a JSON string despite its name). (When JSON.stringify() is passed an object with a toJSON() method, it stringifies the return value of toJSON() instead of the original object. The examples in the previous section took advantage of this feature when they called JSON.stringify() to log model instances.)
http://addyosmani.github.io/backbone-fundamentals/#backbone-basics
Can anyone tell me the difference between both these ways of representing an object
in JSON
notation. I am just confused whether these to achieve the same or there is a difference.
toJSON()
returns a value thatJSON.stringify()
can then convert in to JSON text. I believe this is handy when using things like Date objects. This is from what I remember reading. – Matthew PaxmanJSON.stringify
will calltoJSON
itself to figure out an object's JSON representation. – mu is too short