Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2017年4月.
Symbol.hasInstance は静的データプロパティで、ウェルノウンシンボルの Symbol.hasInstance を表します。instanceof 演算子は右辺オペランドに対して、コンストラクターオブジェクトがオブジェクトをそのインスタンスとして認識するかどうかを判断する際に使用されるメソッドを、このシンボルで探します。
ウェルノウンシンボル Symbol.hasInstance です。
| 書込可能 | 不可 |
| 列挙可能 | 不可 |
| 設定可能 | 不可 |
instanceof 演算子は、object instanceof constructor の返値を計算するために以下のアルゴリズムを使用します。
Because all functions inherit from Function.prototype by default, most of the time, the Function.prototype[Symbol.hasInstance]() method specifies the behavior of instanceof when the right-hand side is a function.
たとえば、次のようにして instanceof の独自の動作を実装することができます。
instanceof キーワードを使ってオブジェクトがクラスのインスタンスであるかどうかを確認するのと同じ方法で、Symbol.hasInstance を使って確認することもできます。
| ECMAScript® 2027 Language Specification # sec-symbol.hasinstance |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年11月13日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.