MathLib.is()

MathLib.is checks if the first argument (or one of its prototypes) is of the type indicated by the second argument.

Examples

Let's say you want to write a function which handles vectors, points and lines. One way would be writing: var type = MathLib.type(x); if (type === 'vector' || type === 'point' || type === 'line') { // do something } This can be abbreviated using the MathLib.is function: if (MathLib.is(x, 'vector')) { // do something } This works because line and point inherit the vector methods.

Tests