Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Small change to prevent confusion between .toJSON and JSON.stringify() #125

Merged
merged 1 commit into from

2 participants

@dietervds

See issue: #124

@addyosmani
Owner

Perfect! Thanks! :)

@addyosmani addyosmani merged commit 414a5e6 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 6 deletions.
  1. +8 −6 index.md
View
14 index.md
@@ -613,16 +613,18 @@ console.log(myAttributes);
It is best practice to use `Model.set()` or direct instantiation to set the values of a model's attributes.
-Accessing `Model.attributes` directly is generally discouraged. Instead, should you need to read or clone data, `Model.toJSON()` is recommended for this purpose. If you would like to access or copy a model's attributes for purposes such as JSON stringification (e.g. for serialization prior to being passed to a view), this can be achieved using `Model.toJSON()`:
+Accessing `Model.attributes` directly is generally discouraged. Instead, should you need to read or clone data, `Model.toJSON()` is recommended for this purpose. If you would like to access or copy a model's attributes for purposes such as JSON stringification (e.g. for serialization prior to being passed to a view), this can be achieved using Model.toJSON(). Remember that this will return an object and JSON.stringify() should be used to get a string representation of the data:
```javascript
var myAttributes = myPhoto.toJSON();
-console.log(myAttributes);
-/* this returns { title: "My awesome photo",
- src:"boston.jpg",
- location: "Boston",
- tags:['the big game', 'vacation']}*/
+console.log(JSON.stringify(myattributes));
+/* this returns:
+ { title: "My awesome photo",
+ src:"boston.jpg",
+ location: "Boston",
+ tags:['the big game', 'vacation']}
+*/
```
####Model.set()
Something went wrong with that request. Please try again.