I want to overwrite the default Backbone Model variable (Backbone.Model) to use my own custom validation methods (isValid, validate) and to add some properties.
_.extend(Backbone.Model, {
isValid: function() { // custom function },
validate: function() { // custom logic }
});
var myModel = Backbone.Model.extend({
// this adds for example properties to my modified Backbone model.
});
Unfortunatly this doesn’t work… when I load the “wrapper, extending”-module with requirejs and create a new Model instance and than call validate. It says that it doesn’t know any validate function…
you have to extend
Backbone.Model.prototyperather thenBackbone.Modelitself as all the methods are prototype methods of the constructor function rather then properties on the model. Though it might be better idea to create a custom BaseModel that will extend the Backbone.Model and implement your custom logic so that if backbone gets updated etc. you will avoid possible conflicts even if in this case they are rather unlikely it’s still considered a better practice to extend base Backbone classes rather then to modify them.