Myster
Myster

Reputation: 18094

How do I override / encapsulate the backbone 'set' method

If I wish to strip out some extra spaces, and ensure http:// is prepended to any input whenever a call like so is made

    myModel.set('url','www.google.com');

Upvotes: 3

Views: 1165

Answers (1)

mumu2
mumu2

Reputation: 671

Agree with @rjsvaljean, but if you really want to override set method for myModel then do it like that:

var MyModel = Backbone.Model.extend({
    set: function(attributes, options) {    
        // 'strip out some extra spaces, and ensure http is prepended' here

        return Backbone.Model.prototype.set.call(this, attributes, options);
    }
});

Upvotes: 4

Related Questions