Ember.js在哪里调用this._super()

Ili*_*oly 17 javascript overriding ember.js

我一直在阅读Ember文档,并且看到_super覆盖时调用方法的位置不一致init.

这是最常见的,也是我到目前为止所使用的

var Foo = Em.Object.extend({
    init: function(){
        this._super();
        // ... my stuff ...
    }
});
Run Code Online (Sandbox Code Playgroud)

昨晚我正在阅读这篇文章并看到了这样做的一个例子

var Bar = Em.Object.extend({
    init: function(){
        // ... my stuff ...
        return this._super();
    }
});
Run Code Online (Sandbox Code Playgroud)

它实际上是Ember.ContainerView代码片段中的一个.

有谁能解释一下?我的代码OCD正在起作用,直到我知道我才能继续前进.

hvg*_*des 14

在链接的文档中

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

_super()在创建descriptionView并将其推送到childViews阵列之后调用.

那是因为超类init实现将采用childViews数组并对其进行处理.如果你_super在添加descriptionView到数组之前调用它,它将不会被任何init处理....

我推断,但这就是它在Sproutcore中的工作方式,Ember从中得出,所以我认为它可能是相同的.