Instanceof operator in Javascript

Source: Internet
Author: User
In JavaScript, The instanceof operator returns a Boolean value indicating whether the object is an instance of a specific class.
Usage:

Result = Object instanceof class

Result is required. Any variable.
Object is required. Any object expression.
Class is required. Any defined object class.

Description
If an object is an instance of class, the instanceof operator returns true. If the object is not an instance of the specified class, or the object is null, false is returned.

Instanceof operator in Javascript
The following example illustrates the usage of the instanceof operator.

function objtest (OBJ) {
var I, T, S = ""; // create a variable.
T = new array (); // create an array.
T ["date"] = date; // fill in the array.
T ["object"] = object;
T ["array"] = array;
for (I in T)
{< br> If (OBJ instanceof T [I]) // check the OBJ class.
{< br> S + = "obj is an instance of" + I + "\ n ";
}< br> else
{< br> S + = "obj is not an instance of" + I + "\ n ";
}< BR >}< br> return (s); // return a string.
}

var OBJ = new date ();
response. Write (objtest (OBJ);

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.