| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/instanceof | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..
instanceof , . , object instanceof constructor , constructor.prototype object.
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
const auto = new Car("Honda", "Accord", 1998);
console.log(auto instanceof Car);
// Expected output: true
console.log(auto instanceof Object);
// Expected output: true
object instanceof constructor
object.
constructor-, .
instanceof , constructor.prototype object.
//
function C() {}
function D() {}
var o = new C();
// true, : Object.getPrototypeOf(o) === C.prototype
o instanceof C;
// false, D.prototype o
o instanceof D;
o instanceof Object; // true, :
C.prototype instanceof Object; // true
C.prototype = {};
var o2 = new C();
o2 instanceof C; // true
// false, C.prototype o
o instanceof C;
D.prototype = new C(); // add C to [[Prototype]] linkage of D
var o3 = new D();
o3 instanceof D; // true
o3 instanceof C; // true, C.prototype o3
: instanceof constructor.prototype, . object ( ) Object.setPrototypeOf __proto__.
instanceof (, ) . , built-ins ( , ..). . , [] instanceof window.frames[0].Array false, Array.prototype !== window.frames[0].Array Array.
, , , . , , Array.isArray(myObj).
, , Node SVGElement myNode instanceof myNode.ownerDocument.defaultView.SVGElement.
:
XPCOM instanceof : obj instanceof xpcomInterface ( Components.interfaces.nsIFile) obj.QueryInterface(xpcomInterface) true QueryInterface . , xpcomInterface obj instanceof. JavaScript , obj instanceof xpcomInterface , obj .
String Date Object instanceof, String Date Object ( Object).
, , , prototype undefined, instanceof Object true.
var simpleStr = " ";
var myString = new String();
var newStr = new String(", ");
var myDate = new Date();
var myObj = {};
simpleStr instanceof String; // false,
myString instanceof String; // true
newStr instanceof String; // true
myString instanceof Object; // true
myObj instanceof Object; // true, , undefined
({}) instanceof Object; // true,
myString instanceof Date; // false
myDate instanceof Date; // true
myDate instanceof Object; // true
myDate instanceof String; // false
mycar Car Object Car , mycar. instanceof , mycar Car Object.
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
var mycar = new Car("Honda", "Accord", 1998);
var a = mycar instanceof Car; // true
var b = mycar instanceof Object; // true
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-relational-operators |
This page was last modified on 17 . 2025 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |