Tags

, , , , , , , ,

Why do we have to use .toJSON() method, and why not send the model to the view to render the template? We could take this topic for a debate and see no one winning it.

There is no much difference between both. Some would argue that one method better than the other in performance aspect, but there is not. _.clone(this.attributes) is all that .toJSON() does in the background, and its such a fast call.

The advantage that .toJSON() has is that, we don’t have to write additional code in your template and access the key value pairs directly like, {{=name}} etc. And if you pass the full model, you can call the model’s custom methods inside the template and access the value like, {{=model.get(‘name’)}}

I would suggest using .toJSON(), so that I won’t make the template heavy, that could affect the application performance.

Advertisements