Results 1 to 5 of 5

Thread: Is not a constructor error

  1. #1
    Ext JS Premium Member
    Join Date
    Feb 2008
    Posts
    312
    Vote Rating
    5
      0  

    Default Is not a constructor error

    When I would like to create new component:

    Code:
               this.basketList = new SM.Basket.List({
                    flex: 1
                });
    I get error:
    Uncaught TypeError: SM.Basket.List is not a constructor.

    What should I change? Is there something with namespaces?

    https://fiddle.sencha.com/#fiddle/1bpp

    (SM.Basket.List is in basketList file which is included before app.js)

  2. #2
    Sencha - Support Team tristan.lee's Avatar
    Join Date
    Mar 2015
    Posts
    1,415
    Vote Rating
    72
      0  

    Default

    Your assignment SM.Basket = Ext.extend(Ext.Panel, {...}); is changing SM.Basket namespace containing your List class to an Ext.Panel, so List no longer exists.
    Tristan Lee
    Sencha Inc - Sustaining Engineer


    Having an issue? Help us help you - be detailed; provide some code; demonstrate with a fiddle (fiddle.sencha.com)

    Embed your fiddle in your post: [FIDDLE]id[/FIDDLE]

  3. #3
    Ext JS Premium Member
    Join Date
    Feb 2008
    Posts
    312
    Vote Rating
    5
      0  

    Default

    If I have:
    Code:
    SM.Basket.List = Ext.extend(Ext.Panel, {...});
    
    SM.Basket = Ext.extend(Ext.Panel, {
         constructor: function (cfg) {
           this.basketList = new SM.Basket.List({});
         }
    ...
    });
    So, first child class is declared, then parent.
    It produce mentioned error. But if i change order, than it works:

    Code:
    SM.Basket = Ext.extend(Ext.Panel, {
         constructor: function (cfg) {
           this.basketList = new SM.Basket.List({});
         }
    ...
    });
    
    SM.Basket.List = Ext.extend(Ext.Panel, {...});
    But it is not true for similar case:

    Code:
    SM.Basket.ListToolbar = Ext.extend(Ext.Toolbar, {...});
    
    SM.Basket.List = Ext.extend(Ext.Panel, {
    initComponent: function () {
          this.add(new SM.Basket.ListToolbar({}));
    }
    });
    Here it works even if child class is defined before parent one. The only difference is that in this example the "SM.Basket.ListToolbar"
    is added on initComponent, while "SM.Basket.List" is added to SM.Basket inside constructor.

    I'm not sure if i understand this. Can you explain a little bit more, please?
    Why defining class order sometimes is important and sometimes not.

  4. #4
    Sencha - Support Team tristan.lee's Avatar
    Join Date
    Mar 2015
    Posts
    1,415
    Vote Rating
    72
      0  

    Default

    Let's simplify the first case. This code is what is giving you trouble:

    Code:
    SM.Basket.List = Ext.extend(Ext.Panel, {...});
    
    SM.Basket = Ext.extend(Ext.Panel, {
         constructor: function (cfg) {
           this.basketList = new SM.Basket.List({});
         }
    ...
    });
    I've broken this down into a basic Object which represents when Ext creates the namespace. You can run this example and observe in the console that the List constructor is called the first time, then when you define the SM.Basket class, you are now changing SM.Basket from an Object that contains other properties (such as your List class) to a Function. Now SM.Basket.List no longer exists.



    When you do it in the different order (like below), SM.Basket gets defined first, and then the assignment of SM.Basket.List now makes List a property of the SM.Basket class.

    Tristan Lee
    Sencha Inc - Sustaining Engineer


    Having an issue? Help us help you - be detailed; provide some code; demonstrate with a fiddle (fiddle.sencha.com)

    Embed your fiddle in your post: [FIDDLE]id[/FIDDLE]

  5. #5
    Ext JS Premium Member
    Join Date
    Feb 2008
    Posts
    312
    Vote Rating
    5
      0  

    Default

    Thank you Tristan, you are great.
    This is the best possible answer, now everything is clear

Similar Threads

  1. Replies: 1
    Last Post: 9 Nov 2015, 6:34 AM
  2. Replies: 0
    Last Post: 2 Oct 2011, 11:19 PM
  3. Replies: 0
    Last Post: 2 Oct 2011, 11:19 PM
  4. Error : Not a constructor
    By hitekshu in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 22 May 2009, 6:42 AM
  5. error:Ext.ContentPanel is not a constructor
    By rg87 in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 26 Mar 2008, 9:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •