PDA

View Full Version : [NOREPRO] Problem with Ext.create() and arrays



aflx
13 Nov 2011, 2:21 AM
REQUIRED INFORMATION


Ext version tested:


Sencha Touch 2 PR2



Browser versions tested against:


Chrome 15 (Mac OSX Lion)




Description:


When creating new instances of the same class, it seems like some class-members acts like static variables.



Steps to reproduce the problem:


create 2 instances of a class with an array-member
get the member of instance1 and push something
same for the second instance



The result that was expected:


two different arrays with different content



The result that occurs instead:


only one array with the same content



Test Case:

Test class



Ext.define("Test", {
config: {
array: []
},

init: function() {
}
});


Test:



var test1 = Ext.create("Test");
test1.getArray().push("bla");

var arr = test1.getArray();

var test2 = Ext.create("Test");
test2.getArray().push("blub");

var arr2 = test2.getArray(); // expected: length == 1, content == "blub"; result: length == 2, content: "bla", "bub"



HELPFUL INFORMATION

Debugging already done:


none



Possible fix:


set the array in the constructor





constructor: function(config) {
this.initConfig(config);
this.callParent([config]);

this.setArray([]);

return this;
}


Operating System:


Mac OSX Lion

mitchellsimoens
13 Nov 2011, 6:45 AM
Objects and Arrays defined like this will be shared across all instances. I'm going to add this as an improvement as it really should copy the Object and Array to a new Object/Array when going through the config Object.