View Full Version : create class behavior

29 Apr 2015, 6:08 AM
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? :D


29 Apr 2015, 7:11 AM
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.