Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by vidja_games

I would like to get an entity's type/class.

For example I know that this works, but its just not useful for what I need to do.
ig.log(portal instanceof EntityPortal);
//returns true as expected

I tried the following but...
ig.log(portal.constructor);
//returns function () 

ig.log(portal.constructor.toString());
//returns function () { "use strict"; }

So apart from making a huge switch containing instanceof or throwing the ClassName into each entity on creation, what can I do to have access to the ClassName?

1 decade ago by Philip

As far as I know there is no way to access the class name. For Steamclash we added the classname to every class per hand as an instance variable. Not a nice way, but it works.

The problem is, that you can't get the name of a variable, so there is no easy automatic way of doing this.

1 decade ago by quidmonkey

You can&039;t do it. Javascript isn't reflexive. Best way is to define a <1> or #.id. Although, if you don't know which type you're passing around, chances are you need to redesign your code.
Page 1 of 1
« first « previous next › last »