On Wed, Feb 23, 2011 at 10:30, omrihar <[email protected]> wrote:
> My problem is the following - after creating several of these groupbox
> objects, it seems that the this.__variables array contains all the
> variables, from all the instances of the object!
> If at the constructor I set this.__variables = [], and use
> console.log(this.__variables) to follow the evolution of the array, after
> every instance is created the variables array holds only the correct
> variables, but then still all the instances just hold the variables of the
> last created groupbox object.
>
> Is this a bug? Am I missing something about extending objects?
>
It's not a bug, but it is confusing. Objects and arrays are stored as
references to a single entity. Therefore, if you initialize a member
variable to an array directly in the variable declaration in the members
section, all of your objects of your defined class will have references to
that same array. To solve this problem, you declare the variable with value
null, and assign it a unique array in the constructor.
Wrong:
qx.Class.define("my.Stuff",
{
members :
{
// This will create an array at class definition time, and provide the
reference
// to that array to every instantiation of my.Stuff
__junk : [ ]
}
}
Right:
qx.Class.define("my.Stuff",
{
construct : function()
{
// Give this instance of my.Stuff a unique array
this.__junk = [ ];
},
members :
{
// Since null is not a reference type, each object will have its own
null value
__junk : null
}
}
Derrell
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel