"inhertiance" via prototype in script file.

Posted by Kyrock on Tue 07 Apr 2009 05:28 AM — 2 posts, 13,351 views.

#0
I'm trying to create a class that's not going to be instantiated and used just for other classes to inherit, but I can't seem to get it to work. Here's what I'm doing:

function TestObject()
  {
  this.testVar = 1;
  this.write = writing;
  function writing()
    {
    world.note("writing from TestObject");
  }
}

TestingObject.prototype = new TestObject();

function TestingObject()
  {
  this.write = writing;
  function writing()
    {
    world.note("should have inherited testVar and the value is: " + this.testVar);
  }
}


then in an alias called test I do:

var t1 = new TestObject();
var t2 = new TestingObject();
t1.write();
t2.write();

t1 notes correctly, but where t2 writes "should have inherited testVar and the value is: undefined"

I'm guessing this is because almost everything in the script file has to be called through a function(not sure if this is correct) and this means the
TestingObject.prototype = new TestObject();
line doesn't get processed. I'm wandering if there is a way to deal with this?
#1
nevermind. I mistyped the var name in the second class...which would explain why I got undefined