3.2.0

Trick while creating new AW object instance

Hi, guys

as you know, in the original AW framework, you can only get a new instance of any AW class with the default no-parameter constructor(at least, i think so). if you wanna instance an object which initialized with various value in runtime, you have to do like this

var obj = new Foo.Foo2.Bar;
obj.setSomeProperty(value);
obj.setSomeOtherProperty(value2);


so i checked the JavaScript1.3 document and i think maybe we can do a little tricky thing to Alex's subclass method in Active.System.Object :)

in line 10:
var constructor = function(){this.init()};

now try to change to this:
var constructor = function(){this.init.apply(this, arguments)};


Then in the init method of any subclass of Active.System.Object, you can retrieve the constructor arguments array while you try to new an instance of this (sub)class, within the exactly same syntax to get the arguments while calling a function in JavaScript spec 1.3

it works well on my computer.
my enviorment is: Pentium II 500, Windows XP SP1, IE 6.0.2800.1106.xp SP2.030422-1633

and the same good within MyIE2 0.9.10

Hope it will be useful, if so, Enjoy it :)
Copenhagen
May 12,
If you implement this you have to take care of clone method as well (similar way). It is also a performance hit, which is the main reason why I decided not having the constructor arguments at all.
Alex (ActiveWidgets)
May 12,
really?
would you like to give more hints about the performance issue?
Copenhagen
May 12,
I don't remember exact figures but I had the impression that calling this.init.apply(this, arguments) vs this.init() will cost you say 15mks vs 5mks. Not a big deal - but you are adding this to ALL objects, which you create with the framework.

Also when you are adding arguments to the constructor - it implies that you will actually do something in the constructor function. This is what I am trying to avoid at all cost. Either add things to the prototype or on demand when they are actually needed.
Alex (ActiveWidgets)
May 12,
I just realised that it may sound too much negative. Actually it is a valid approach and apply() function works fine in all major browsers. I just recommend adding this at the point where you actually need it instead of the root class (for performance reasons).
Alex (ActiveWidgets)
May 12,

This topic is archived.

See also:


Back to support forum