Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small change to prevent confusion between .toJSON and JSON.stringify(…

…), as per issue: #124
  • Loading branch information...
commit 6adf47a34de1a4799fa08bd7f766f970205cda53 1 parent 6b57894
Dieter Van der Stock dietervds authored
Showing with 8 additions and 6 deletions.
  1. +8 −6 index.md
14 index.md
View
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.