Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!