Getting component type from object in craftyjs

Say I have code like the following.

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

Can someone tell me if there is a function to check the type of an object?

Example:

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

or

 Crafty.getComponents(obj)=="SomeType" 
+4
source share
1 answer

Ah found from the file Crafty.js that there is a .has () function for checking the 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`). */ 
+4
source

Source: https://habr.com/ru/post/1439519/


All Articles