Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. JavaScript
  3. JavaScript リファレンス
  4. 標準組み込みオブジェクト
  5. Reflect
  6. Reflect.has()

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。

View in EnglishAlways switch to English

Reflect.has()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2016年9月⁩.

静的なReflect.has() メソッドは、機能としてはin 演算子のように動作します。

試してみましょう

const object1 = {  property1: 42,};console.log(Reflect.has(object1, "property1"));// Expected output: trueconsole.log(Reflect.has(object1, "property2"));// Expected output: falseconsole.log(Reflect.has(object1, "toString"));// Expected output: true

構文

Reflect.has(target, propertyKey)

引数

target

プロパティを探す対象のオブジェクト。

propertyKey

チェックするプロパティ名。

返値

対象がプロパティを持つかどうかを示すBoolean 値。

例外

targetObject でなかった場合、TypeError が発生します。

解説

Reflect.has メソッドは、オブジェクトプロパティがあるかをチェックします。機能としてはin 演算子のように動作します。

Reflect.has() の使用

js
Reflect.has({ x: 0 }, "x"); // trueReflect.has({ x: 0 }, "y"); // false// プロトタイプチェーンのプロパティがあるため、true が返るReflect.has({ x: 0 }, "toString");// Proxy with .has() handler methodobj = new Proxy(  {},  {    has(t, k) {      return k.startsWith("door");    },  },);Reflect.has(obj, "doorbell"); // trueReflect.has(obj, "dormitory"); // false

Reflect.has は継承されたプロパティについてtrue を返し、これはin 演算子と同様です。

js
const a = { foo: 123 };const b = { __proto__: a };const c = { __proto__: b };// The prototype chain is: c -> b -> aReflect.has(c, "foo"); // true

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-reflect.has

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp