:: Forum >>

Can anyone explain the ActiveWidgets code?

I am new to the whole prototyping thing in Javascript. I have some questions regarding the code. I was going through the object.js file (if you download the code it is one of the js files in there) and in that file I saw something like this.

Active.System.Object.subclass = function(){
var constructor = function(){this.init()}; //1
for (var i in this) {constructor[i] = this[i]} //2
constructor.prototype = new this(); //3
constructor.superclass = this; //4
return constructor; //5

My first question is this. First of all the constructor variable gets all the properties of the this object. If that is so then why do we need to use prototype to inherit on top of all the copying (lines 2 and 3)? Why do we need both and not just one? (I commented out one of the lines and the code doesn't work. So it looks like you need both the lines).

My second question is about line 3. In this case the prototype points to 'this' object which is basically the constructor for the Active.System.Object class. So if I substitute the word this with Active.System.Object shouldn't the code work? why does it throw error?
In other words I substituted the line no 3 with this.
constructor.prototype = new Active.System.Object(); //3
Any help is really appreciated.

Thank you..
Thursday, December 29, 2005
Thursday, December 29, 2005

This topic is archived.

Back to support forum

Forum search