I'll try to think of examples and come back to it tomorrow.
For now: One thing that I'm still not clear on is when to wrap .get/.set.
Should I always write my own getters/setters and only use .get/.set internally? Right now I'm only wrapping them when the attributes need special processing, which leads to an inconsistent-feeling API.
I've got an 'Organization' model and a 'Person' model. I want to use them interchangeably in some templates, so I need to be able to get their names in a consistent way.
An Organization just has a 'name', but a Person has a 'first_name' and a 'last_name'. I've been using a 'displayName' method to encapsulate the difference; would it make more sense to do something like:
var Person = Backbone.Model.extend({
initialize: function() {
var name = this.get('first_name') + ' ' + this.get('last_name');
this.set({ name: name }, { silent: true });
}
});
For now: One thing that I'm still not clear on is when to wrap .get/.set.
Should I always write my own getters/setters and only use .get/.set internally? Right now I'm only wrapping them when the attributes need special processing, which leads to an inconsistent-feeling API.