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

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

0

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

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

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 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!