Ember.js where to call this._super()

后端 未结 1 1221
傲寒
傲寒 2020-12-30 03:56

I\'ve been going through the Ember documentation and am seeing an inconsistency in where the _super method is being called when overriding init.

相关标签:
1条回答
  • 2020-12-30 04:33

    In the documentation linked

     init: function() {
        var childViews = this.get('childViews');
        var descriptionView = App.DescriptionView.create();
        childViews.pushObject(descriptionView);
        this.addButton();
        return this._super();
      },
    

    _super() is called AFTER the descriptionView is created and pushed onto the childViews array.

    That's because the superclass init implementation is going to take the childViews array and do stuff with it. If you called _super before adding the descriptionView to the array, it wouldn't get processed by whatever init does....

    I'm inferring, but that's the way it works in Sproutcore, from which Ember derives, so I think it's probably the same.

    0 讨论(0)
提交回复
热议问题