Skip to content

Instantly share code, notes, and snippets.

@DarrylD
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarrylD/8984714 to your computer and use it in GitHub Desktop.
Save DarrylD/8984714 to your computer and use it in GitHub Desktop.
Simple override of a Backbone class, View in this case. Can be applied to modal, collection, etc...
Backbone.View = (function(View) {
// Define the new constructor
Backbone.View = function(attributes, options) {
// New constructor stuff here...
// Call default constructor
View.apply(this, arguments);
// Add some callbacks
this.on('event', this.someCallback, this);
};
// Clone static properties
_.extend(Backbone.View, View);
// Clone prototype
Backbone.View.prototype = (function(Prototype) {
Prototype.prototype = View.prototype;
return new Prototype;
})(function() {});
// Update constructor in prototype
Backbone.View.prototype.constructor = Backbone.View;
return Backbone.View;
})( Backbone.View );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment