A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf below:

Reflect.getPrototypeOf() - JavaScript | MDN

Reflect.getPrototypeOf()

Baseline Widely available

静的な Reflect.getPrototypeOf() メソッドは、Object.getPrototypeOf() とほぼ同じメソッドです。これは指定したオブジェクトのプロトタイプ (つまり、内部の [[Prototype]] プロパティの値) を返します。

試してみましょう
const object1 = {
  property1: 42,
};

const proto1 = Reflect.getPrototypeOf(object1);

console.log(proto1);
// Expected output: Object {  }

console.log(Reflect.getPrototypeOf(proto1));
// Expected output: null
構文
Reflect.getPrototypeOf(target)
引数
target

プロトタイプを取得する対象のオブジェクトです。

返値

与えられたオブジェクトのプロトタイプです。継承されたプロパティがない場合、null を返します。

例外

target が Object でない場合に TypeError がスローされます。

解説

Reflect.getPrototypeOf メソッドは、指定したオブジェクトのプロトタイプ (つまり、内部の [[Prototype]] プロパティの値) を返します。

例 Reflect.getPrototypeOf() の使用
Reflect.getPrototypeOf({}); // Object.prototype
Reflect.getPrototypeOf(Object.prototype); // null
Reflect.getPrototypeOf(Object.create(null)); // null
Object.getPrototypeOf() との比較
// Object の結果は同じです
Object.getPrototypeOf({}); // Object.prototype
Reflect.getPrototypeOf({}); // Object.prototype

// ES5 上では非Objectの結果は両方とも例外です
Object.getPrototypeOf("foo"); // Throws TypeError
Reflect.getPrototypeOf("foo"); // Throws TypeError

// ES2015 上では Reflect のみ例外で、Object は 非Object を Object として扱います
Object.getPrototypeOf("foo"); // String.prototype
Reflect.getPrototypeOf("foo"); // Throws TypeError

// To mimic the Object ES2015 behavior you need to coerce
Reflect.getPrototypeOf(Object("foo")); // String.prototype
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4