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

150
Vistas
List all class methods in Javascript

The best way to explain my problem is through the below code:

class SomeClass {
  SomeMethod() {
    console.log("SomeMethod was called");
  }
}

var someInstance = new SomeClass();

// The below expression expected to return True but is returns False
console.log(
  someInstance.hasOwnProperty("SomeMethod")
);

// The below expression is expected to include SomeMethod in the return list, but it doesn't
console.log(
  Object.keys(someInstance)
);

// The below expression is expected to include SomeMethod in the return list, but it doesn't
console.log(
  Object.getOwnPropertyNames(someInstance)
);

// The below expression works fine which confrms that the function exists.
someInstance.SomeMethod();

CodeSandbox link

I would expect Object.keys() or Object.getOwnPropertyNames() to return all properties including methods defined in the class definition of the class from which this object was constructed but for some reason neither does.

If neither of these functions works in such a scenario then how can I list all methods of a class instance?

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

0

You Can create custom function to acheive this

class SomeClass {
  SomeMethod() {
    console.log("SomeMethod was called");
  }
}

var someInstance = new SomeClass();
function getMethods(obj) {
  return Object.getOwnPropertyNames(Object.getPrototypeOf(obj))
    .filter(m => 'function' === typeof obj[m])
}
console.log(getMethods(someInstance))

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