--- title: Symbol.hasInstance slug: Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance tags: - JavaScript - Property - Symbol translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance ---
Symbol.hasInstance
— известный символ, который используется для определения является ли объект экземпляром конструктора. Этот символ используется для изменения поведения оператора {{jsxref("Operators/instanceof", "instanceof")}}.
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.
Поведение instanceof
может быть изменено, например, следующим образом:
class MyArray { static [Symbol.hasInstance](instance) { return Array.isArray(instance); } } console.log([] instanceof MyArray); // true
Спецификация | Статус | Комментарий |
---|---|---|
{{SpecName('ES2015', '#sec-symbol.hasinstance', 'Symbol.hasInstance')}} | {{Spec2('ES2015')}} | Изначальное определение. |
{{SpecName('ESDraft', '#sec-symbol.hasinstance', 'Symbol.hasInstance')}} | {{Spec2('ESDraft')}} |
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("javascript.builtins.Symbol.hasInstance")}}