If you look at the source code, the get function simply calls this.attributes[name] .
http://backbonejs.org/docs/backbone.html#section-31
The advantage, however, is at least twice:
1) a compatible API that reduces the amount of code you write
2) the ability to override the get method and provide more complex access control
For example, there are several plug-ins for the trunk that redefine the operation of models to provide the capabilities of nested models. itβs very easy for them to let you write the get method as follows:
model.get("submodel.attr")
and analyze attr submodel submodels. Without the get method, it would be harder to do this according to the API.
The main advantage of this is encapsulation. Until JavaScript provides true get / set properties that allow us to write code for getters and seters, we will stick to working methods such as Backbone get and set .
Derick bailey
source share