tags:

views:

150

answers:

1

In the asp.net ajax library, there is a line that make me confused.

Type.prototype.registerClass = function Type$registerClass(typeName, baseType, interfaceTypes) {

//..

this.prototype.constructor = this;

//.. }

I known that (this.prototype.constructor === this) == true, so what is significance of this line? I remove the line, and test the library with some code. It seems it is ok.

can any javascript guy tell why? Thanks Fred

+1  A: 

I'm not familiar with the asp.net libs, but:

A common pattern in Javascript, especially when trying to simulate class based systems, is to reassign the prototype object to an instance of another object, rather than just adding properties to the prototype object JS gives you. One issue with this is that it gives you the wrong constructor - unless perhaps one resets with a 'correct' value.

Justin Love