Reflect.get()
静的な Reflect.get()
メソッドは、オブジェクト (target[propertyKey]
) からプロパティを関数として取得するように動作します。動作します。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
構文
Reflect.get(target, propertyKey[, receiver])
引数
target
- プロパティを取得する対象のオブジェクト。
propertyKey
- 設定するプロパティ名。
receiver
省略可- ゲッターがあった場合、
target
への呼び出しで使用するthis
の値を提供します。Proxy
とともに使用すると、target
から継承しているオブジェクトにすることができます。
返値
プロパティの値です。
例外
解説
Reflect.get
メソッドはオブジェクトのプロパティを取得します。機能としてはプロパティアクセサー構文と似ています。
例
Reflect.get()
の使用
// オブジェクト
let obj = { x: 1, y: 2 }
Reflect.get(obj, 'x') // 1
// 配列
Reflect.get(['zero', 'one'], 1) // "one"
// Proxy with a get handler
let x = {p: 1};
let obj = new Proxy(x, {
get(t, k, r) {
return k + 'bar'
}
})
Reflect.get(obj, 'foo') // "foobar"
仕様書
ブラウザーの互換性
BCD tables only load in the browser