Functions and examples of isPrototypeOf functions in JavaScript
This article mainly introduces the functions and examples of isPrototypeOf functions in JavaScript. This article describes the functions, usage methods, and examples of isPrototypeOf functions. For more information, see
In JavaScript, The isPrototypeOf function method returns a Boolean value indicating whether the object exists in the prototype chain of another object. Usage:
The Code is as follows:
Object1.isPrototypeOf (object2)
Object1 is a required instance of an object.
Object2 is required. Another object will check its prototype chain.
If the prototype chain of object2 contains object1, The isPrototypeOf Function Method in JavaScript returns true.
The prototype chain can be used to share functions between different instances of the same object type.
If object2 is not an object or object1 does not appear in the prototype chain of object2, The isPrototypeOf Function Method in JavaScript returns false.
The following example describes how to use the isPrototypeOf function in JavaScript.
The Code is as follows:
Function test (){
Var re = new RegExp (); // initialize the variable.
Return (RegExp. prototype. isPrototypeOf (re); // return true.
}