相关疑难解决方法(0)

电话和申请有什么区别?

使用callapply调用函数有什么区别?

var func = function() {
  alert('hello!');
};
Run Code Online (Sandbox Code Playgroud)

func.apply(); VS func.call();

上述两种方法之间是否存在性能差异?当它最好使用callapply,反之亦然?

javascript performance function dynamic

3012
推荐指数
21
解决办法
69万
查看次数

在Backbone中访问父类

我需要initialize从继承的MyModel类中调用父类的方法,而不是像我今天那样完全覆盖它.

我怎么能这样做?

这是我的代码现在看起来的样子:

BaseModel = Backbone.Model.extend({
    initialize: function(attributes, options) {
        // Do parent stuff stuff
    }
});

MyModel = BaseModel.extend({
    initialize: function() {
        // Invoke BaseModel.initialize();
        // Continue doing specific stuff for this child-class.
    },
});
Run Code Online (Sandbox Code Playgroud)

javascript oop inheritance class backbone.js

67
推荐指数
4
解决办法
4万
查看次数

Backbone View继承 - 调用parent导致递归

我有一个三个Backbone View类继承:

var preventRecursion = 0;

var parentView = Backbone.View.extend({

  initialize: function(){
    console.log('parentView');
  }
});

var nestedChildView = parentView.extend({

  initialize: function(){

    if (++preventRecursion == 5) {throw "Recursion"};

    console.log('nestedChildView');
    this.constructor.__super__.initialize.apply(this);          
  }
});

var nestedNestedChildView = nestedChildView.extend({

  initialize: function(){
    console.log('nestedNestedChildView');
    this.constructor.__super__.initialize.apply(this);          
  }
});
Run Code Online (Sandbox Code Playgroud)

当我尝试创建nestedNestedChildView时:

var t = new nestedNestedChildView();
Run Code Online (Sandbox Code Playgroud)

我得到无限递归:这是jsfiddle

inheritance backbone.js backbone-views

7
推荐指数
1
解决办法
9194
查看次数

扩展自定义Backbone.Marionette视图.如何隐含地引发原型事件/ onRender?

我有一个观点:

var MultiSelectCompositeView = Backbone.Marionette.CompositeView.extend({

    events: {
        'click .listItem': 'setSelectedOnClick'
    },

    onRender: function () {
        console.log("MultiSelectCompositeView onRender has executed.");
    }
});
Run Code Online (Sandbox Code Playgroud)

我有另一个扩展MultiSelectCompositeView的视图:

var VideoSearchView = MultiSelectCompositeView.extend({

    events: _.extend(MultiSelectCompositeView.prototype.events, {
        'input @ui.searchInput': 'showVideoSuggestions',
        'click button#hideVideoSearch': 'destroyModel',
        'contextmenu @ui.videoSearchResults': 'showContextMenu'
    },

    onRender: function () {

        this.ui.playlistActions.append((new PlaySelectedButtonView()).render().el);
        this.ui.playlistActions.append((new SaveSelectedButtonView()).render().el);

        //  TODO: Is there a better way to do this?
        MultiSelectCompositeView.prototype.onRender.call(this, arguments);
    }
});
Run Code Online (Sandbox Code Playgroud)

我对VideoSearchView不会隐式扩展MultiSelectCompositeView的事件以及VideoSearchView必须手动调用MultiSelectCompositeView的onRender方法这一事实感到不满.

Backbone.Marionette有什么东西可以让我以更加无缝的方式扩展我的自定义视图吗?

javascript backbone.js marionette

4
推荐指数
1
解决办法
4539
查看次数

骨干继承,合并render()函数

所以我现在有这样的情况:

app.Ui.ModalView = Backbone.View.extend({
    events: {

    },

    initialize: function() {

    },

    render: function() {
        var that = this;
        var model = this.model.toJSON();

        that.$el.html(that.template(_.extend(this.params || {}, {
            model: model,
        })));
        return this;
    }
});
Run Code Online (Sandbox Code Playgroud)

然后是继承的视图:

app.Views.childView = kf.Ui.ModalView.extend({

    template: JST["templates/app/blah/blah-edit.html"],
    events: {

    },
    initialize: function() {
        var that = this;
        this.events = _.extend({}, app.Ui.ModalView.prototype.events, this.events);
        app.Ui.ModalView.prototype.initialize.apply(this, arguments);
    },

render: function(){
// add extra logic in this render function, to run as well as the inherited render function?
}

});
Run Code Online (Sandbox Code Playgroud)

所以,我不想覆盖父级render() …

backbone.js

3
推荐指数
1
解决办法
1868
查看次数