P
Piotr K
I'm really confused, please take a look at code below:
function Class(obj)
{
obj.Extend = function(obj) {
this.__parent__ = new Object();
for(p in this) {
this.__parent__[p] = this[p];
}
for(p in obj) {
this[p] = obj[p];
}
return this;
}
return obj;
}
function A()
{
return Class({ name : "Class A" })
}
function B()
{
return A().Extend({ name : "Class B" });
}
function C()
{
return B().Extend({ name : "Class C" });
}
var a = A();
var b = B();
var c = C();
alert(b.__parent__.name);
It should alert "Class A" and it does, but only in Internet Explorer
and Opera - strangly in Firefox it alerts "Class B".. If I remove line
"var c = C()" or move it above "var b = B()", Firefox also alerts
"Class A". I guess it has something to do with "this" pointer, but I
don't know what - theoretically it should work as it is (in fact it
doest, but as I mentioned only in IE and Opera)
Does anyone have an idea why is it working so strangly and what to do
with it ?
Thanks for any help
function Class(obj)
{
obj.Extend = function(obj) {
this.__parent__ = new Object();
for(p in this) {
this.__parent__[p] = this[p];
}
for(p in obj) {
this[p] = obj[p];
}
return this;
}
return obj;
}
function A()
{
return Class({ name : "Class A" })
}
function B()
{
return A().Extend({ name : "Class B" });
}
function C()
{
return B().Extend({ name : "Class C" });
}
var a = A();
var b = B();
var c = C();
alert(b.__parent__.name);
It should alert "Class A" and it does, but only in Internet Explorer
and Opera - strangly in Firefox it alerts "Class B".. If I remove line
"var c = C()" or move it above "var b = B()", Firefox also alerts
"Class A". I guess it has something to do with "this" pointer, but I
don't know what - theoretically it should work as it is (in fact it
doest, but as I mentioned only in IE and Opera)
Does anyone have an idea why is it working so strangly and what to do
with it ?
Thanks for any help