javascript - ExtJS 6 : Should I use the config object?

标签 javascript extjs extjs6

我正在使用 ExtJS 6 构建应用程序。 我已经阅读了指南、教程和最佳实践技巧。 但我还不明白的是,为什么要使用配置对象?

配置:

Ext.define('MyProject.foo.Bar', {
    extends: 'Ext.window.Window',

    ...

    config: {
        title: 'My title'
    }
});

没有配置:

Ext.define('MyProject.foo.Bar', {
    extends: 'Ext.window.Window',

    ...

    title: 'My title'
});

两者都按预期工作。 谁能告诉我区别和可能的好处?

最佳答案

Class System 中均有描述指南:

  • Configurations are completely encapsulated from other class members
  • Getter and setter methods for every config property are automatically generated into the class prototype during class creation if methods are not already defined.
  • The auto-generated setter method calls the apply method (if defined on the class) internally before setting the value. You may override the apply method for a config property if you need to run custom logic before setting the value. If your apply method does not return a value, the setter will not set the value. The update method (if defined) will also be called when a different value is set. Both the apply and update methods are passed the new value and the old value as params.

关于javascript - ExtJS 6 : Should I use the config object?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32689189/

相关文章:

Javascript 如何在输入 3 个字符后显示自动建议结果

javascript - 使用 Element.querySelector 的意外结果

javascript - 在 Sencha Touch 中按需加载 NestedList 的项目

javascript - 为什么使用 MooTools 定义伪事件时,Firefox 中的事件未定义?

javascript - Bower_components 未使用 Express static 加载

javascript - Extjs store.load 不调用

javascript - 动态更改 extjs jsonreader 字段

javascript - ExtJS6:在网格面板的列中传递整个对象或 2 个字段

javascript - ExtJS 6.2 从存储更新 TreeGrid 数据,无需从服务器重新加载

javascript - Tagfield 卷轴不工作