4

假设我有如下代码。

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

谁能告诉我是否有检查对象类型的功能?

前任:

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

或者

Crafty.getComponents(obj)=="SomeType"
4

1 回答 1

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`).
    */
于 2012-10-13T06:51:37.290 回答