There is nothing objective misuse of Backbone.Model for this purpose, but no matter what it seems suspicious. The model comes with extra baggage, which does not belong to the class of type “service” or “utility”.
Instead, I defined a more general, evented base class for functionality that does not quite match the Backbone Model-View-Collection-Router paradigm.
define(['backbone', 'underscore'], function(Backbone, _) { var Class = function() { this.initialize.apply(this, arguments); };
The class behaves like other Backbone objects, since it can be extend ed, its instances have an initialize constructor and support events. One of your examples, a localization service, might look something like this:
var LocalizationService = Class.extend({ initialize: function(url) { this.url = url; this.fetch(); }, fetch: function({ var self = this; $.ajax({ url:this.url, success: function(response) { self.response = response; self.trigger('fetch:complete', self, response);
source share