instanceof Operator

Using the instanceof operator, you can test if an object was created with a specific constructor function.

function Hero(){}
var h = new Hero();
var o = {};
h instanceof Hero;

h instanceof Object;

o instanceof Object;

Note that you don't put parentheses after the function name (don't use h instanceof Hero()). This is because you're not invoking this function, but just referring to it by name, as for any other variable.

Related Tutorial
Follow Us #
Contents +