The use of instanceof in JavaScript

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.