0

I need to extend class dynamically and use this code:

Calc.grid.Table["Table"+key] = function(config) {
        config = config || {};
        Ext.applyIf(config,{
                id: 'calc-grid-table'+key
                ,baseParams: { 
                    action: 'mgr/calc/calcGetTable'+key
                    ,query: 'Calc'+key 
                }
        });
        Calc.grid.Table["Table"+key].superclass.constructor.call(this,config)
};
Ext.extend(Calc.grid.Table["Table"+key],Calc.grid.Table);
Ext.reg('calc-grid-table'+key,Calc.grid.Table["Table"+key]);

but it gives me an error:

Uncaught TypeError: Cannot read property 'superclass' of undefined

I tried to change it to this

this.superclass.constructor.call(this,config)

but error is

Uncaught SyntaxError: Unexpected identifier

The problem is in dynamic literals. When I do like this it works fine

Calc.grid.Table.Table21 = function(config) {
        config = config || {};
        Ext.applyIf(config,{
                id: 'calc-grid-table'+21
                ,baseParams: { 
                    action: 'mgr/calc/calcGetTable'+21
                    ,query: 'Calc'+21
                }
        });
        Calc.grid.Table.Table21.superclass.constructor.call(this,config)
};
Ext.extend(Calc.grid.Table.Table21,Calc.grid.Table);
Ext.reg('calc-grid-table'+21,Calc.grid.Table.Table21);

How can I fix it? What am I doing wrong?

Thanx in advance.

artask
  • 429
  • 7
  • 18
  • Most likely `key` changes before the constructor is called. Can you show some more code? – user123444555621 May 05 '12 at 10:11
  • @Pumbaa80, Thank you so much! That was a problem. key was iterating in a loop. Now I have new exeption "Uncaught TypeError: Cannot call method 'stopEditing' of undefined". Do you have any idea what can cause this? – artask May 05 '12 at 13:43

1 Answers1

0

You're key variable being used in your constructor isn't scoped to that function, so it is possible that is can be changed before the constructor is called. You can use Ext's createDelegate to tie the variable to the function so that it can't change on you:

Calc.grid.Table["Table"+key] = function(key, config) {
    config = config || {};
    Ext.applyIf(config,{
            id: 'calc-grid-table'+key
            ,baseParams: { 
                action: 'mgr/calc/calcGetTable'+key
                ,query: 'Calc'+key 
            }
    });
    Calc.grid.Table["Table"+key].superclass.constructor.call(this,config)
}.createDelegate(this, [key], 0);
Sean Adkinson
  • 8,425
  • 3
  • 45
  • 64