假设我有一个如下代码。
Crafty.c("SomeType",{//do something... });
var obj=Crafty.e("SomeType");
有谁能告诉我是否有检查对象类型的功能?
前:
Crafty.isComponent(obj,"SomeType")==true
或
Crafty.getComponents(obj)=="SomeType"
答案 0 :(得分:4)
啊从Crafty.js文件中发现有一个.has()函数来检查组件。 :)
/**@
* #.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`).
*/