Menu

#223 Objects

open
nobody
engine (98)
5
2004-12-06
2004-12-06
lipe775
No

How about an 'extends' and 'implements' clause in
javascript?

That would allow some very neat features like:

function MyPerson( name ) extends Person
{
this.name = name;
this.hitPoints = 10;
this.onWalk = function( ... ) {}

this.slash = function( enemy ){ enemy.fireEvent(
"onSlash" );
}
var p = new MyPerson( "personName" );
CreatePerson( p, "person.rss", false );

Person p = GetPersonByName( "personName" );
Debug( p.hitPoints );

Person p2 = GetPersonByName( "enemy" );
p.slash( p2 );
===============

===============
function MyTrigger() implements Trigger
{
this.onTouch = function( ... ) {}
this.onClick = function( ... ) {}
this.tile = "";// etc
}
===============
And, when adding triggers, a "reference object" field
should be supported.

I know a some of this can be achieved by using the
prototype clause, but a more close interaction between
the engine functions and the user's objects would
improve Sphere a lot.

Away better than work with strings :D

Discussion

  • Brian Robb

    Brian Robb - 2004-12-08

    Logged In: YES
    user_id=387078

    Not going to happen.
    JavaScript supports inheritance already via using prototype

     
  • Nobody/Anonymous

    Logged In: NO

    This is more a forum question/request than a bug, please ask
    in the forums.
    Why not try:
    http://www.kevlindev.com/tutorials/javascript/inheritance/

     
  • Tung Nguyen

    Tung Nguyen - 2006-09-13

    Logged In: YES
    user_id=1206940

    It can _all_ be done by prototyping, actually. Refer to the
    official JS guide for details:

    http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide

    Also, Sphere _uses_ the SpiderMonkey JS engine. The
    JavaScript syntax is something that's managed in that
    project, by those guys: Sphere just uses it.

     

Log in to post a comment.

MongoDB Logo MongoDB