gosu

The difference between typeof and typeis in Gosu


My coworker and I have tried running tests but they haven't been conclusive. The question is, what is the difference between typeof and typeis in the Gosu language? Examples:

typeis: if(some_obj typeis some_class) { do xyz }

typeof: if(typeof some_obj == some_class) { do abc }

Can anyone settle our discussion? We are under the impression that one of these keywords checks for if an object is a member of a class and any of its children vs. checking if an object is a member of a class, period (ie, not also its children).


Solution

  • Both operators are used to retrieve or test an item’s type.

    Use the typeof operator to retrieve the run-time type of a data item. Comparing the retrieved type to a subtype of the retrieved type evaluates to false

    A typeis expression tests the type of an object. If the object is of either the tested type or a subtype of the tested type, the expression evaluates to true.