proto.isPrototypeOf(obj) returns true when proto appears anywhere in obj’s prototype chain.
It is about objects, not constructor functions. For class or constructor checks, people often use instanceof. To read the direct prototype, use Object.getPrototypeOf.
Syntax
Call obj.isPrototypeOf() like this. Start with this line.
JavaScript
proto.isPrototypeOf(obj)
Call
What it does
proto.isPrototypeOf(obj)
True if proto is in obj’s chain.
Object.prototype.isPrototypeOf({})
True for normal objects that inherit from Object.prototype.
Object.getPrototypeOf(obj) === proto
Checks only the direct prototype, not the whole chain.
Call on the candidate prototype. Pass the object you want to test.
Library declarations
JavaScript
proto.isPrototypeOf(obj)
JavaScript
object.isPrototypeOf(v: any): boolean
Parameters
Parameter
Description
obj
Required. The object whose prototype chain you want to search.
Return Value
Return Value
Description
boolean
true if this value is a prototype of obj; otherwise false.
JavaScript Examples
Check a Prototype Link
Create an object with Object.create and test the chain.
JavaScript
var animal = { kind: "animal" };
var dog = Object.create(animal);
dog.bark = function () { return "woof"; };
console.log(animal.isPrototypeOf(dog));
console.log(Object.prototype.isPrototypeOf(dog));
console.log(dog.isPrototypeOf(animal));
Direct link.animal is the prototype of dog, so the first check is true.
Longer chain. Normal objects also inherit from Object.prototype.
Direction matters.dog is not a prototype of animal.
Works for Deeper Chains
Grandparent prototypes still count.
JavaScript
var a = { level: "a" };
var b = Object.create(a);
var c = Object.create(b);
console.log(a.isPrototypeOf(c));
console.log(b.isPrototypeOf(c));
console.log(Object.getPrototypeOf(c) === b);