Best Practices concerning initComponent() in Ext.define()

前端 未结 3 1985
广开言路
广开言路 2020-12-13 07:05

I\'m writing all my components in ExtJS\'s new MVC fashion using Ext.define().

I struggle a bit whether define properties inside of initComponent(

3条回答
  •  眼角桃花
    2020-12-13 07:28

    Personal practice, I will declare variables in the properties area when the

    • variables defining magnitude, like x, y, width, height
    • variables that awaiting to be overridden, or customizable, like title, saveBtnTxt, url, fields, iconCls
    • some constants, that will have special prefixes so will not be overridden so easily

    Then I will declare items, listeners, this.on, Ext.apply(me, {..}) or anything that requires the scope of the obj (this, me), to sit inside my initComponent. Or stuff that should be modified/overridden before everything is setting up so user will not break my component by overriding some of the important variables.

    Of course that'll serve as my guidance. 2 cents

    EDIT

    About the ugly this, I have used the variable me widely in my app, and it looks a lot cleaner than this. It benefits me from changing scopes less frequently too.

提交回复
热议问题