Is always equivalent use one or the other?
These prints in console same things
class Model extends Backbone.Model
defaults:
some: 'thing'
other: 'item'
model = new Model
console.log model.attributes
console.log model.toJSON()
js respectively. The rest of your application code should be divided into modules that can live under their own modules directory. A module is an encapsulated group of structures (for the purposes of our post, Backbone structures) that work cohesively to provide a subset of functionality in your application.
The Backbone. js View el method defines the element that is used as the view reference. this. el is created from the view's tagName, className, id and attributes properties, if specified.
You can use the Backbone. Model without jQuery, but Backbone.
toJSON() is a standard method that the JavaScript JSON serializer looks for when serializing an object.
In the context of Backbone, if you override toJSON in your model you can change the format of values which get sent to the server when saving. For example you could filter out read only fields like time stamps.
attributes is the JavaScript object containing the model data, that's what gets altered when you use model.set(). Except if you don't use set() to alter values, then you bypass all the events and loose some of the benefits of backbone. So only use attributes directly if you know what you're doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With