From: Robert R. <rai...@us...> - 2000-10-28 20:45:14
|
There's also a bit of inconsistency with making the children array null. Because once you remove all the children, the array is not null, but has a length of 0. So, in your widget, you will have to check for a null array and a array of length 0. I don't understand why the array can't be initialized to an empty array. Later, Robert <rai...@us...> > I think I've found a fix for the problem with children arrays being shared > between widgets made with the widgetX model. > > The problem: > > Widget.prototype = new DynLayer() > > When this is done, the properties of the base DynLayer are *shared* with > every Widget made with the constructor. > > Most of these shared properties are reassigned to unique ones when > createElement is called on the Widget. However, the children array is not, > and it gives the effect that all Widgets share the same children array. > > So I've posted a patch for DynLayer and DynDocument that assigns the > this.children array only when you use addChild. DynLayer-based widgets > won't have a children array until you add at least one child. > > I also made changes to removeChild, removeAllChildren, etc. that check for > the existence of the child array before proceeding. > > This should ensure that the children array is a unique object for each > widget, and not the common one in the Widget prototype. Then you can safely > use WidgetX to simulate inheritance without the shared-properties problem. > > The only consideration is if you build a widget that manipulates the > children array, you should test it it exists first (it's initially set to > null until you use addChild). > > I've only tested it on a few IBS and GUI widgets, but it seems to work > across the board. I've posted the patch for review. > > scottandrew > > > > > > > ------ > Scott Andrew LePera > DHTML / Scripting / CGI and other neat stuff > sc...@sc... > http://www.scottandrew.com |