NOTE. My CoffeeScript is rusty, so I answer this in JS, but the idea needs to be translated.
Obviously, one way to resolve this issue is to give all your views a parent class, and then put methods like handleError into this class. However, if you are looking for a more βmixinβ as a way to add methods, you can also do this.
Baseline views are initialized with an argument to the extend method, for example:
var MyView = Backbone.View.extend({ someMethod: function(){ doSomething();} });
This argument is not magical; it's just a JS object, so you can extend it with _.extend, for example:
var myCommonMethods = { handleError: function ... } var MyView = Backbone.View.extend(_({ someMethod: function(){ doSomething();} }, myCommonMethods));
The advantage of this approach is that you can βmixβ as many sets of methods as you want, whereas if you use the parent class, you are much more limited. However, the parent class approach is simpler:
var BaseView = { handleError: function ... } var MyView = BaseView.extend({ someMethod: function(){ doSomething();} });
so it really depends on your specific needs.
Personally, in my code I use both approaches: I have BaseView, that all my views are expanding, and I use extremely general logic (for example, our template system, to which most of our representations apply). Then I have "mix-ins" of various sets of methods that add extra functionality.
For example, I have a mixed set of methods for all views that have a select element like their el; this allows these views to have some kind of base class for them, but it also has a common set of methods (for example, they all have a selectOption method that allows you to add the "selected" attribute to a specific option inside the el view). Hope this helps.