Permalink
Browse files

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

…), as per issue: #124
  • Loading branch information...
1 parent 6b57894 commit 6adf47a34de1a4799fa08bd7f766f970205cda53 @dietervds dietervds committed May 5, 2012
Showing with 8 additions and 6 deletions.
  1. +8 −6 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()

0 comments on commit 6adf47a

Please sign in to comment.