> Ok...when i change the line this.value = this.dummy(value) to this.value =
> this.prototype.dummy(value) the code runs.
Are you sure this works, because IMO it shouldn't. Try to instantiate your object in a normal manner and see this line blow up. The
prototype property of the object is not the same as the
prototype property of the
Constructor object. Each object created using a constructor has an *implicit* reference to it's Constructors' prototype. It works in your case because in your
CREATE function you end up assigning the prototype property of the Constructor object (TestConstructor) to the prototype property of the newly created object.
The only way to make your
dummy() function not blow up is to call it as
TestConstrutror.prototype.dummy() and not
this.prototype.dummy() for the reasons mentioned above.
As far as your issue is concerned, I think that as long as an object isn't created, the context for property lookup using the prototype chain is not set up. So when the call to dummy function inside the constructor is made, a implicit link has not been set up between the object which is *yet to be created* and the prototype property of the Constructor. This can be verified by the fact that once the Constructor exits and a new object is returned, the call to
dummy() works as it should. E.g.
TestConstructor.prototype.dummy = function (value) {
return value * 2;
};
function TestConstructor(value) {
this.value = this.prototype.dummy(value); // won't work
};
var a = new TestConstructor(1);
a.dummy(); // This works!
Just my 2 cents...