-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON #15
Comments
I also don't like this naming convention, but it actually has nothing to do with this library. |
Yeah I will probably hide toJSON and expose toJS which similarly does a deep conversion to plain JS objects, but doesn't muck with JSON. — On Wed, Jul 30, 2014 at 11:32 AM, Felix Kling notifications@github.com
|
@leebyron : This was actually more of a reply to @benjamingr :) Not sure what you mean by "hiding" in this case. The method should definitely exist to make JSON conversion easier. I just dislike the choice of the method name in general ;) |
Hide as in not document beyond "supports JSON.stringify"— On Wed, Jul 30, 2014 at 11:40 AM, Felix Kling notifications@github.com
|
@fkling but |
@benjamingr: No, I'm relatively sure that var foo = [{
toJSON: function() { return JSON.stringify({bar: 42}); }
}];
JSON.stringify(foo); // "["{\"bar\":42}"]" instead of "[{"bar":42}]" Again, I don't like the naming convention either, but it's not the fault of this library. Other libraries / frameworks such as Backbone.js, do the exact same thing. I was about to create an issue about that, until I realized that |
It appears that you are right @fkling, this is what the proposal page says too. It's a poor naming choice. |
The name |
…t with stringed or parsed JSON. The latter is less confusing. Solves #15
toJSON is no longer described at all in the type definitions file, but continues to exist as an alias for toJS so that JSON.stringify still behaves correctly. I also changed fromJSON to fromJS to solve for the same ambiguity. Thanks for highlighting this point of confusion, @benjamingr! |
Hi, toJS is confusing to me that we are writing in JS already. A class instance with methods is still a JS object, isn't it? |
Hi, I've noticed you use
.toJSON()
to convert to JavaScript objects.JSON is a data serialization format, converting it
toJSON
would have been to also call.stringify
on it.The objects produced by this call are also not always valid JSON or are even encodable/decodable as JSON.
I would recommend renaming
.toJSON
. I don't have any particularly good ideas on what to though.The text was updated successfully, but these errors were encountered: