| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf | [Back] [Original] |
Get to know MDN better
isPrototypeOf() Object
:
isPrototypeOf() instanceof object instanceof AFunction object AFunction AFunction.prototype
function Foo() {}
function Bar() {}
Bar.prototype = Object.create(Foo.prototype);
const bar = new Bar();
console.log(Foo.prototype.isPrototypeOf(bar));
// : true
console.log(Bar.prototype.isPrototypeOf(bar));
// : true
isPrototypeOf(object)
(this) object this false
Object.prototype null isPrototypeOf() object false this object this
baz Baz.prototype Bar.prototypeFoo.prototypeObject.prototype
class Foo {}
class Bar extends Foo {}
class Baz extends Bar {}
const foo = new Foo();
const bar = new Bar();
const baz = new Baz();
// :
// foo: Foo --> Object
// bar: Bar --> Foo --> Object
// baz: Baz --> Bar --> Foo --> Object
console.log(Baz.prototype.isPrototypeOf(baz)); // true
console.log(Baz.prototype.isPrototypeOf(bar)); // false
console.log(Baz.prototype.isPrototypeOf(foo)); // false
console.log(Bar.prototype.isPrototypeOf(baz)); // true
console.log(Bar.prototype.isPrototypeOf(foo)); // false
console.log(Foo.prototype.isPrototypeOf(baz)); // true
console.log(Foo.prototype.isPrototypeOf(bar)); // true
console.log(Object.prototype.isPrototypeOf(baz)); // true
isPrototypeOf() instanceof
baz Foo.prototype
if (Foo.prototype.isPrototypeOf(baz)) {
// do something safe
}
Foo.prototype baz baz Foo baz Foo.prototype baz Foo
class Foo {
#value = "foo";
static getValue(x) {
return x.#value;
}
}
const baz = { __proto__: Foo.prototype };
if (Foo.prototype.isPrototypeOf(baz)) {
console.log(Foo.getValue(baz)); // TypeError: #value
}
class Foo {
#value = "foo";
static getValue(x) {
return x.#value;
}
static isFoo(x) {
return #value in x;
}
}
const baz = { __proto__: Foo.prototype };
if (Foo.isFoo(baz)) {
// baz Foo
console.log(Foo.getValue(baz));
}
| ECMAScript 2027 LanguageSpecification # sec-object.prototype.isprototypeof |
Objectassign()create()defineProperties()defineProperty()entries()freeze()fromEntries()getOwnPropertyDescriptor()getOwnPropertyDescriptors()getOwnPropertyNames()getOwnPropertySymbols()getPrototypeOf()groupBy()hasOwn()is()isExtensible()isFrozen()isSealed()keys()preventExtensions()seal()setPrototypeOf()values()Object/Function| Web Proxy Viewer | New URL | Original Page |