4

Let's say I have a code like the following.

Crafty.c("SomeType",{//do something... });
var obj=Crafty.e("SomeType");

Can anyone tell me whether there is a function to check the type of the object?

Ex:

Crafty.isComponent(obj,"SomeType")==true

or

Crafty.getComponents(obj)=="SomeType"
Sanka Darshana
  • 1,391
  • 1
  • 23
  • 41

1 Answers1

4

Ah found out from the Crafty.js file that there is a .has() function to check for a component. :)

    /**@
    * #.has
    * @comp Crafty Core
    * @sign public Boolean .has(String component)
    * Returns `true` or `false` depending on if the
    * entity has the given component.
    *
    * For better performance, simply use the `.__c` object
    * which will be `true` if the entity has the component or
    * will not exist (or be `false`).
    */
Sanka Darshana
  • 1,391
  • 1
  • 23
  • 41