News for hackers. Stuff that matters.
Re:Revesiting Backbone.js View Rendering by pselbert on Wednesday March 20, 2013 @10:04PM (#5412292)
There are numerous benefits to using a presenter, or at least a "renderContext" object. Most conversion, formatting, predicates, and lazy attributes won't come through with toJSON(). The performance penalty is negligible compared to the benefit of testable presenter methods, logic out of the view, etc.

Performance isn't the only thing to consider.

Re:Revesiting Backbone.js View Rendering by wprater on Wednesday March 20, 2013 @12:55PM (#5408495)
I agree that putting all that logic and template vars into a template is confusing. Hard to create mocks of what the HTML should actually be structured like. Im using Jade so I can be terse and pre-compiling the templates. While in my Backbone application, I apply DOM-like rendering with Plates.js.
Re:Revesiting Backbone.js View Rendering by zimbatm on Wednesday March 20, 2013 @11:05AM (#5407668)
I'm not familiar with Backbone but isn't `model.toJSON()` unnecessarily removing useful data types (like Date) that aren't available in JSON ?
Re:Revesiting Backbone.js View Rendering by papercrane on Wednesday March 20, 2013 @11:36AM (#5407870)
You're probably thinking of `JSON.stringify()`. `model.toJSON()` just returns a clone of the models attributes object.
Re:Revesiting Backbone.js View Rendering by zimbatm on Wednesday March 20, 2013 @11:56AM (#5408043)
So `model.toJSON()` isn't supposed to return a JSON-compatible data structure ?
Re:Revesiting Backbone.js View Rendering by papercrane on Wednesday March 20, 2013 @12:38PM (#5408357)
It's supposed to return an object that is suitable for turning into JSON, but it won't convert any of items members. JSON.stringify relies on the toJSON functions of the members to serialize themselves.
Re:Revesiting Backbone.js View Rendering by lopatin on Wednesday March 20, 2013 @11:07AM (#5407679)
Why is using 'model.toJSON()' overkill?