Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Jscript
➜ "inhertiance" via prototype in script file.
|
"inhertiance" via prototype in script file.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Kyrock
(20 posts) Bio
|
| Date
| Tue 07 Apr 2009 05:28 AM (UTC) |
| 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? | | Top |
|
| Posted by
| Kyrock
(20 posts) Bio
|
| Date
| Reply #1 on Tue 07 Apr 2009 05:43 AM (UTC) |
| Message
| | nevermind. I mistyped the var name in the second class...which would explain why I got undefined | | 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.
12,495 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top