Last active
August 29, 2015 13:56
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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