Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

374
Vistas
In ES6, how do you check the class of an object?

In the ES6, if I make a class and create an object of that class, how do I check that the object is that class?

I can't just use typeof because the objects are still "object". Do I just compare constructors?

Example:

class Person {
  constructor() {}
}

var person = new Person();

if ( /* what do I put here to check if person is a Person? */ ) {
  // do stuff
}
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Can't you do person instanceof Person?

Comparing constructors alone won't work for subclasses

over 4 years ago · Santiago Trujillo Denunciar

0

Just a word of caution, the use of instanceof seems prone to failure for literals of built-in JS classes (e.g. String, Number, etc). In these cases it might be safer to use typeof as follows:

typeof("foo") === "string";

Refer to this thread for more info.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda