Why getters and setters in Backbone models?

Why are there getters and setters with Backbone models? There are no private / protected attributes, so getters and setters are a little useless for encapsulation. I know that they are useful for checking, but other than that, what is their usefulness if we can get around them?

+7
source share
1 answer

set does not just do something lower.

 this.attributes["key"] = value; 

If you get around it, you will miss all the other functions that it performs here .

It currently has 2 functions.

1. It calls the _validate method before the value is assigned to the attributes. indicate this .

2.It fires a change event if you are listening to an attribute change.

If they add additional features in the future, you may lose them if you bypass set .

+11
source share

All Articles