JavaScript: Function.prototype[Symbol.hasInstance]

By Xah Lee. Date: . Last updated: .

New in JS2015.

f[Symbol.hasInstance]( obj )
Return true if the value of f.prototype is in the prototype chain of obj. Else, false.

[see Prototype and Inheritance]

[see Symbol Tutorial]

The following are equivalent:

Example of buildin function.

const ar = [3,4];

console.log( Array[ Symbol.hasInstance ](ar) ); // true
console.log( ar instanceof Array ); // true
console.log( Array.prototype.isPrototypeOf ( ar ) ); // true

Example of user-defined function.

function F () { }

let ff = new F;

console.log( F[ Symbol.hasInstance ](ff) ); // true
console.log( ff instanceof F ); // true
console.log( F.prototype.isPrototypeOf ( ff ) ); // true

[see “instanceof” Operator]

[see Symbol Tutorial]

JS in Depth

JS in Depth

JS Obj Ref


JS Obj Ref