Better way to call superclass method in ExtJS

后端 未结 6 1440
梦如初夏
梦如初夏 2020-12-24 06:30

All the ExtJS documentation and examples I have read suggest calling superclass methods like this:

MyApp.MyPanel = Ext.extend(Ext.Panel, {
  initComponent: f         


        
6条回答
  •  攒了一身酷
    2020-12-24 07:05

    You could use this little known Javascript feature (arguments.callee):

    MyApp.MyPanel = Ext.extend(Ext.Panel, {
        constructor: function() {
            // Do your thing
            this.thing = 1;
    
            // Call super
            arguments.callee.superclass.constructor.apply(this, arguments);
        }
    });
    

    see MDC documentation

    Edit: Actually, this isn't going to work with initComponent because it isn't the constructor. I always override the constructor, personally (despite what Ext JS examples suggest). Will continue to think about this one a bit.

提交回复
热议问题