The use of instanceof in JavaScript
Detects that an object is not an instance of another object
function Laker () {} function Bull () {} var la = new Laker (); alert (La instanceof Laker);
Return Result: True
function Laker () {}laker.prototype = {}; function Bull () {} var la = new Laker (); Bull.prototype = Laker.prototype; Alert (La instanceof Bull);
Return Result: True
function Laker () {}laker.prototype = {}, function Bull () {}bull.prototype ={paly:function () {alert ("Play"),}}, var bu =new bu ll (); Bu.paly ();
Return result: "Play ball" check if an instance is of a certain type
function Laker () {}laker.prototype = {}; var la = new Laker (); alert (La instanceof Object);
Return Result: True Summary: Instanceof detects whether an object A is an instance of another object B is the principle of viewing object B's prototype pointing to an object that is on the [[prototype]] chain of object A. Returns true if it is, or false if it is not. There is a special case, however, when the prototype of object B is null, it will be an error (similar to a null pointer exception).
The use of instanceof in JavaScript