[StackOverflow] How to organise common code
http://stackoverflow.com/questions/8681166/how-to-organise-common-code
by Atinux
HTML
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
JavaScript
// Create a Basic View which have all of generic methods
var BasicView = Backbone.View.extend({
restful_destroy_method: function () {
console.log('Called restful destroy method !');
this.model.destroy();
this.remove();
return false
}
});
// View which herits the methods of BasicView
var ExampleView = BasicView.extend({
destroy: function () {
this.restful_destroy_method();
}
});
// Model for the example
var Model = Backbone.Model.extend();
// Create a view and call his destroy method()
var view = new ExampleView({ model: new Model });
view.destroy();