Home >Web Front-end >JS Tutorial >Function and usage examples of isPrototypeOf function in JavaScript_javascript skills

Function and usage examples of isPrototypeOf function in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:57:141316browse

The isPrototypeOf function method in JavaScript returns a Boolean value indicating whether the object exists in the prototype chain of another object. How to use:

Copy code The code is as follows:

object1.isPrototypeOf(object2)

Among them, object1 is a required option, an instance of an object.
object2 is required, another object whose prototype chain will be checked.

If the prototype chain of object2 contains object1, then the isPrototypeOf function method in JavaScript returns true.
Prototype chains can be used to share functionality between different instances of the same object type.
If object2 is not an object or object1 does not appear in the prototype chain in object2, the isPrototypeOf function method in JavaScript will return false.

The following example illustrates the usage of isPrototypeOf function method in JavaScript.

Copy code The code is as follows:

function test(){
var re = new RegExp();
return (RegExp.prototype.isPrototypeOf(re)); //Return true.
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn