Object.getPrototypeOf()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Object.getPrototypeOf()
メソッドは、指定されたオブジェクトのプロトタイプ (つまり、内部プロパティ [[Prototype]]
の値) を返します。
試してみましょう
const prototype1 = {};
const object1 = Object.create(prototype1);
console.log(Object.getPrototypeOf(object1) === prototype1);
// Expected output: true
構文
js
Object.getPrototypeOf(obj)
引数
obj
-
プロトタイプを取得したいオブジェクト。
返値
指定されたオブジェクトのプロトタイプです。何も継承していないオブジェクトの場合は null
です。
例
getPrototypeOf の使用
js
const proto = {};
const obj = Object.create(proto);
Object.getPrototypeOf(obj) === proto; // true
オブジェクト以外の型変換
仕様書
Specification |
---|
ECMAScript® 2026 Language Specification # sec-object.getprototypeof |