Skip to content

Commit

Permalink
types+grammar: ch4, fixing wording per @maxhoffmann, closing getify#328
Browse files Browse the repository at this point in the history
  • Loading branch information
getify committed Feb 13, 2015
1 parent c6d5612 commit ac683b8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion types & grammar/ch4.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ a.toJSON = function() {
JSON.stringify( a ); // "{"b":42}"
```

It's a very common misconception that `toJSON()` should return a the JSON stringification representation. That's probably incorrect, unless you're wanting to actually stringify the `string` itself (usually not!). `toJSON()` should return the actual regular value (of whatever type) that's appropriate, and `JSON.stringify(..)` itself will handle the stringification.
It's a very common misconception that `toJSON()` should return a JSON stringification representation. That's probably incorrect, unless you're wanting to actually stringify the `string` itself (usually not!). `toJSON()` should return the actual regular value (of whatever type) that's appropriate, and `JSON.stringify(..)` itself will handle the stringification.

In other words, `toJSON()` should be interpreted as "to a JSON-safe value suitable for stringification," not "to a JSON string" as many developers mistakenly assume.

Expand Down

0 comments on commit ac683b8

Please sign in to comment.