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

179
Visualizações
Getting available methods/properties for various types in javascript

To see the methods available to an object I am able to do:

console.log(Object.getOwnPropertyNames(Object));

But then why doesn't it give the properties when I pass it an instance of a particular object type (I hope that is the correct terminology?). For example, in the following n has one method called toFixed but it doesn't show up when trying to get the property names.

let n = 1234.567;
console.log(n.toFixed(1));
console.log(Object.getOwnPropertyNames(n));

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

getOwnPropertyNames, as it sounds, gets only the own properties of the object.

But numbers are primitives, not objects - and toFixed is on Number.prototype, not on Number instances. The number has no own properties.

console.log(Object.getOwnPropertyNames(Number.prototype));

For another example, with a proper object:

class X {
  protoMethod(){}
}
const x = new X();

// Empty:
console.log(Object.getOwnPropertyNames(x));
// The prototype has the own-property of the method:
console.log(Object.getOwnPropertyNames(X.prototype));

about 4 years ago · Juan Pablo Isaza Relatório

0

Try Object.getPrototypeOf. All the methods are defined in the prototype of the object.

console.log(Object.getPrototypeOf(n));
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