View Full Version : maps and arrays in config set by reference

19 Dec 2012, 1:34 PM
I am not sure this is a bug, or design. I expected items in the config section of a class definition to initialize corresponding instance variables, and they do. However, for objects and arrays, the instance variables are set to a reference to the corresponding class variable, not to a new instance of object or array. I would expect that they should be set to a copy of the default.

Ext.define('testclass', {
config: {
'props':{}, // instance variable is set to this by refernce, not by copy
'foo': 7

var testConfig = function(){
var A = Ext.create('testclass')
A.props.bar = 7
A.foo = 3
var B = Ext.create('testclass')
console.log('B bar ' + B.props.bar)
console.log('B foo ' + B.foo

B bar 7
B foo 7

19 Dec 2012, 6:03 PM
This is by design. Copying is too expensive and too complicated. For example, if the passed object were an instance of a particular class then how would you copy it without potentially losing something?

However, in cases where the reference type is used as a config for a more complex class (such as a component, store or proxy) the original config is replaced on a per instance basis with the fully instantiated version.

You may find this relevant: