|
"inhertiance" via prototype in script file.
|
Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Kyrock
(20 posts) 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? | top |
|
| Posted by |
Kyrock
(20 posts) 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 | 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
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )