Results 1 to 2 of 2

Thread: create class behavior

  1. #1
    Sencha User fischel's Avatar
    Join Date
    Sep 2007

    Default create class behavior

    I define a simple class with an array and a string. With this I create two objects and make some changes on the properties of the second object.
    Now I take a look at the first object and I see the array is changed too and the string not - both are objects ?!?

    Ext.define('Base', {
        rebels: [],
        location: 'Yavin'
    var b1 = Ext.create('Base');
    var b2 = Ext.create('Base');
    b2.rebels.push('Luke', 'Leia', 'Han');
    b2.location = 'Hoth';
    console.log(b1.rebels.length); // 3
    console.log(b1.location); // Yavin

    Bug or feature? Or do I miss to read same docs?


  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL


    When you create an instance, complex properties (arrays/objects) will be shared unless otherwise taken care of. In your code, you are sharing the rebels array.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:

    Posts are my own, not any current, past or future employer's.

Similar Threads

  1. Replies: 8
    Last Post: 28 Jan 2013, 12:38 PM
  2. Showing class names in the debugger (rather than Ext.apply.create.Class)
    By cdamon in forum Sencha Touch 2.x: Discussion
    Replies: 1
    Last Post: 20 Dec 2012, 9:54 AM
  3. [FIXED] Architect behavior when renaming class (impact on revision control)
    By jptrainor in forum Sencha Architect 2.x: Bugs
    Replies: 5
    Last Post: 23 Aug 2012, 8:41 AM
  4. Replies: 4
    Last Post: 23 Aug 2011, 6:14 PM
  5. Having a strange behavior after I close my own EditorGrid Class.
    By bullfish in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 15 Aug 2011, 12:34 AM

Posting Permissions

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