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

159
Vistas
Check if inherited class has method (and not it's base)

i.e.

class A {
    do_something(){ throw Exception("Not implemented") }
}

class B extends A{
   ...
}

When checking typeof B.do_something === 'function' it gives true because of inheritance. So, how can we check whether B has itself defined do_something method(function)?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As defined in object references, this shows its directly defined methods/properties:

Object.getOwnPropertyNames(YourClass.prototype)
about 4 years ago · Juan Pablo Isaza Denunciar

0

I don't think there is an built-in "class API" way to do this. But it's simple enough when remembering that classes are just syntactic sugar for JS's prototype system.

Here we have:

B.prototype.hasOwnProperty("do_something") // false
A.prototype.hasOwnProperty("do_something") // true

And in practice if you have an object which is an instance of the class, you can substitute that for B.prototype or A.prototype in the above expressions.

about 4 years ago · Juan Pablo Isaza 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