JS: Function.prototype[Symbol.hasInstance]

By Xah Lee. Date: .

New in ES2015.

f[Symbol.hasInstance] ( obj )

Return true if the value of f.prototype is in the prototype chain of obj. Else, false.

[see JS: “this” Binding]

[see JS: Prototype and Inheritance]

[see JS: 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 JS: “instanceof” Operator]

[see JS: Symbol Tutorial]

Reference

ECMAScript 2015 §Fundamental Objects#sec-function.prototype-@@hasinstance

JS Function

  1. Define Function
  2. Arrow Function ⭐
  3. Function Params
  4. “arguments” Object
  5. Rest Params ⭐
  6. Arg Default Value ⭐
  7. Arg Destructure ⭐
  8. f Declaration vs Expression
  9. Closure
  10. f call apply bind
  11. Functional Programing
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog