最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Overriding fetch() method in backbone model - Stack Overflow

programmeradmin2浏览0评论

I would like to override the default fetch() method in a Backbone model, thus calling it only when needed.

Something like this:

Account.Check = Backbone.Model.extend({
    model : Account.Item,

    url : Settings.Url.checkAccount,

    fetch : function(options) {         
                if (someCondition()) {
                    // do some stuff
            } else {
               super.fetch(options);
                }
    }
});

My question is how to provide the same behaviour as the default fetch() method in the // do some other stuff part?

I would like to override the default fetch() method in a Backbone model, thus calling it only when needed.

Something like this:

Account.Check = Backbone.Model.extend({
    model : Account.Item,

    url : Settings.Url.checkAccount,

    fetch : function(options) {         
                if (someCondition()) {
                    // do some stuff
            } else {
               super.fetch(options);
                }
    }
});

My question is how to provide the same behaviour as the default fetch() method in the // do some other stuff part?

Share Improve this question edited Sep 18, 2012 at 7:15 Drejc asked May 3, 2012 at 7:38 DrejcDrejc 14.3k16 gold badges75 silver badges108 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 33

This should do it...

fetch : function(options) {         
           if (someCondition()) {
              // do some stuff
           } else {
              this.constructor.__super__.fetch.apply(this, arguments);
              // Or (less flexible)
              Backbone.Model.prototype.fetch.apply(this, arguments);    
           }
         }
发布评论

评论列表(0)

  1. 暂无评论