R
Robert
Hi!
So far I have been doing "inheritance" in Javascript like this:
******
function TestObject(value)
{
this.value = value;
}
function ExtendedObject(value1, value2)
{
TestObject.call(this, value1);
this.value2 = value2;
}
ExtendedObject.prototype = new TestObject();
******
This works okay, but I have a wrong feeling with the TestObject
constructor being called just to "inherit" from it and a second time
again later. Especially if the TestObject function really expected a
value parameter. Is there a way so I can "inherit" without doing
ExtendedObject.prototype = new TestObject();
I looked at http://www.crockford.com/javascript/inheritance.html
but the constructor is called twice in that framework too.
So far I have been doing "inheritance" in Javascript like this:
******
function TestObject(value)
{
this.value = value;
}
function ExtendedObject(value1, value2)
{
TestObject.call(this, value1);
this.value2 = value2;
}
ExtendedObject.prototype = new TestObject();
******
This works okay, but I have a wrong feeling with the TestObject
constructor being called just to "inherit" from it and a second time
again later. Especially if the TestObject function really expected a
value parameter. Is there a way so I can "inherit" without doing
ExtendedObject.prototype = new TestObject();
I looked at http://www.crockford.com/javascript/inheritance.html
but the constructor is called twice in that framework too.