El bien conocido símbolo Symbol.hasInstance
es usado para determinar si un constructor reconoce un objeto como su instancia. El comportamiento del operador instanceof
puede ser personalizado con este símbolo.
Atributos de la propiedad Symbol.hasInstance |
|
---|---|
Sobrescribir | No |
Numerable | No |
Configurable | No |
Ejemplos
Usted puede implementar un comportamiento personalizado para el operador instanceof
tal que así:
class MyArray {
static [Symbol.hasInstance](instance) {
return Array.isArray(instance);
}
}
console.log([] instanceof MyArray); // true
Specifications
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) La definición de 'Symbol.hasInstance' en esta especificación. |
Standard | Initial definition. |
ECMAScript (ECMA-262) La definición de 'Symbol.hasInstance' en esta especificación. |
Living Standard |
Browser compatibility
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 51 | (Yes) | 50 (50) | Sin soporte | ? | ? |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | ? | ? | (Yes) | 50.0 (50) | Sin soporte | ? | ? |