Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda