C
Crazy Cat
Hi, I'm trying to understand prototype chains. The following code in
IE 6 does not give expected results -
var myobject;
function BaseObject()
{
}
BaseObject.prototype.a = 3;
var myobject = new Object();
myobject.prototype = new BaseObject();
alert(myobject.a);
I would expect to see that myobject.a = 3 however the code indicates
that it is undefined. However myobject.prototype.a is equal to 3. I
thought that the compiler was supposed to search the prototype chain
until it found a definition for a if it's not found in the object.
What am I missing?
IE 6 does not give expected results -
var myobject;
function BaseObject()
{
}
BaseObject.prototype.a = 3;
var myobject = new Object();
myobject.prototype = new BaseObject();
alert(myobject.a);
I would expect to see that myobject.a = 3 however the code indicates
that it is undefined. However myobject.prototype.a is equal to 3. I
thought that the compiler was supposed to search the prototype chain
until it found a definition for a if it's not found in the object.
What am I missing?