Czytasz angielską wersję tego artykułu, ponieważ nie ma jeszcze tłumaczenia dla tego języka. Pomóż nam przetłumaczyć ten artykuł!

The isPrototypeOf() method checks if an object exists in another object's prototype chain.

isPrototypeOf() differs from the instanceof operator. In the expression "object instanceof AFunction", the object prototype chain is checked against AFunction.prototype, not against AFunction itself.




The object whose prototype chain will be searched.

Return value

A Boolean indicating whether the calling object lies in the prototype chain of the specified object.

Errors thrown

A TypeError is thrown if prototypeObj is undefined or null.


The isPrototypeOf() method allows you to check whether or not an object exists within another object's prototype chain.


This example demonstrates that Baz.prototype, Bar.prototypeFoo.prototype and Object.prototype exist in the prototype chain for object baz:

function Foo() {}
function Bar() {}
function Baz() {}

Bar.prototype = Object.create(Foo.prototype);
Baz.prototype = Object.create(Bar.prototype);

var baz = new Baz();

console.log(Baz.prototype.isPrototypeOf(baz)); // true
console.log(Bar.prototype.isPrototypeOf(baz)); // true
console.log(Foo.prototype.isPrototypeOf(baz)); // true
console.log(Object.prototype.isPrototypeOf(baz)); // true

isPrototypeOf() method, along with the instanceof operator particularly comes in handy if you have code that can only function when dealing with objects descended from a specific prototype chain, e.g., to guarantee that certain methods or properties will be present on that object.

For example, check if baz object descends from Foo.prototype:

if (Foo.prototype.isPrototypeOf(baz)) {
  // do something safe


Specification Status Comment
ECMAScript 3rd Edition (ECMA-262) Standard Initial definition.
ECMAScript 5.1 (ECMA-262)
The definition of 'Object.prototype.isPrototypeOf' in that specification.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Object.prototype.isPrototypeOf' in that specification.
ECMAScript Latest Draft (ECMA-262)
The definition of 'Object.prototype.isPrototypeOf' in that specification.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
isPrototypeOfChrome Full support YesEdge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes


Full support  
Full support

See also