ExtJS 5:initConfig 方法和 Observable mixin

ExtJS 5: initConfig method & Observable mixin

因为我似乎没有在 Sencha Forum 上得到任何答案,我只是在这里重复我的问题:

我目前正在从 4.2.1 迁移到 5.1.0.107,但在理解某些内容时遇到问题:

Sencha dev evant states here initConfig 只需要从 类 中的构造函数手动调用,它不使用 Observable mixin。

docs 中 Observable mixin 的第一个示例通过手动调用它来说明。

运行 文档中的代码导致异常(hasListeners 未定义),可以通过将 this.mixins.observable.constructor.call(this, config); 放入构造函数来解决。

而且在我看来 initConfig 可以从文档的示例代码中删除而没有任何缺点(至少 none 我能够重现)...

下面两个代码的唯一区别在于 Employee 构造函数...

Erroneous fiddle(从文档中复制的代码)

Ext.define('Employee', {
    mixins: ['Ext.mixin.Observable'],

    config: {
        fullName: ''
    },

    constructor: function(config) {
        this.initConfig(config);  // We need to initialize the config options when the class is instantiated
    },

    quitJob: function() {
        this.fireEvent('quit');
    }
});

var newEmployee = Ext.create('Employee', {
    fullName: 'Ed Spencer',

    listeners: {
        quit: function() {
            alert(this.getFullName() + " has quit!");
        }
    }
});

try {
    newEmployee.quitJob(); // Throws exception since hasListener is undefined
} catch (exc) {
    alert('Error occurred: ' + exc.message);
}

Working fiddle(删除了 initConfig 并正确初始化了 mixin)

Ext.define('Employee', {
    mixins: ['Ext.mixin.Observable'],

    config: {
        fullName: ''
    },

    constructor: function(config) {
        // Make code work by removing call to initConfig and initializing the observable mixin
        //this.initConfig(config);  // We need to initialize the config options when the class is instantiated
        this.mixins.observable.constructor.call(this, config);
    },

    quitJob: function() {
        this.fireEvent('quit');
    }
});

var newEmployee = Ext.create('Employee', {        
    fullName: 'Ed Spencer',

    listeners: {
        quit: function() {
            alert(this.getFullName() + " has quit!");
        }
    }
});

try {
    newEmployee.quitJob(); // Will log 'Ed Spencer has quit!'
} catch (exc) {
    alert('Error occurred: ' + exc.message);
}

如果有人能回答以下问题,我将非常高兴:

谢谢并致以最诚挚的问候

这里摘录自 ExtJs 5.1 Upgrade Guide -

"Unification of Ext.util.Observable and Ext.mixin.Observable APIs As mentioned in What’s New in Ext JS 5.1, Ext JS 5.1 still has two Observable classes (Ext.mixin.Observable, and Ext.util.Observable), but their API differences have been eliminated. There is only one exception: Ext.mixin.Observable calls initConfig in its constructor whereas Ext.util.Observable uses the legacy Ext.apply approach to copy config object properties onto the instance. We recommend that applications use Ext.mixin.Observable going forward, but we will continue to support Ext.util.Observable for the foreseeable future since many classes internal to the framework and in user code depend upon its behavior."