JS: Function .prototype [Symbol .hasInstance]
(new in ECMAScript 2015)
f[Symbol.hasInstance](obj)-
Return
trueif the value off.prototypeis in the Prototype Chain of obj. Else,false.[see Symbol Tutorial]
The following are equivalent:
f[Symbol.hasInstance](obj)obj instanceof ff.prototype.isPrototypeOf(obj)
[see instanceof Operator]
// Example Symbol.hasInstance on a buildin function const xx = [3, 4]; console.assert( Array[Symbol.hasInstance](xx), ); console.assert( xx instanceof Array, ); console.assert( Array.prototype.isPrototypeOf(xx), ); // Example Symbol.hasInstance on a user-defined function function F() {} const xx = new F(); console.assert( F[Symbol.hasInstance](xx), ); console.assert( xx instanceof F, ); console.assert( F.prototype.isPrototypeOf(xx), );