[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Jscript
. . -> [Subject]  "inhertiance" via prototype in script file.

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

"inhertiance" via prototype in script file.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Kyrock   (20 posts)  [Biography] bio
Date Tue 07 Apr 2009 05:28 AM (UTC)  quote  ]
Message
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?
[Go to top] top

Posted by Kyrock   (20 posts)  [Biography] bio
Date Reply #1 on Tue 07 Apr 2009 05:43 AM (UTC)  quote  ]
Message
nevermind. I mistyped the var name in the second class...which would explain why I got undefined
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


1,484 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]