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

186
Views
JavaScript - Confusion between global classes and inheritance

Total begginer who learns JS here. I don't understand why when you declare a variable it doesn't TOTALLY inherit of it's parent class methods, for e.g.:

// I initiate an array (my question is the same for all type of vars)
var myArr = ["foo", "bar"]

// Let's say I call a random function of the parent class Array
console.log(Array.isArray(myArr)); // true

// Since I assume that myArr inherited of the COMPLETE LIST of Array's methods, I should be able to do this:
console.log(myArr.isArray()); // Uncaught TypeError

Why don't the variables inherit of all of the methods of it's parent classes? Instead of that you need to mix between the fonctions of Array and myArr. They should be identitical on the two sides, no?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Array.isArray can also be called on non-arrays, so calling it from the instance of other classes would not have the method, resulting in a runtime error. Basically if you knew it was an array and it would be callable, you would not need to call it.

That is why it is NOT on the Array prototype and NOT callable from the instance.

const a = null
a.isArray() // bad
Array.isArray(a) // good

Developers have the option in Javascript to add methods to the class, the instance (aka prototype), or both. In this case it was only added to the class, not the instance.

It could have been added to the prototype of Object, but then it still would not be on the instances of boolean, number, string, symbol, or undefined.

about 4 years ago · Juan Pablo Isaza Report

0

You need to pass an array as a parameter to the isArray function.
Eg:

console.log(myArr.isArray(myArr))
about 4 years ago · Juan Pablo Isaza Report

0

When you declare a variable it is an instance of a Class, there is not inheritance.

When you declare a class that extends another class is where inheritance occurs.

Array.isArray() is a static property of the JavaScript Array object.

Usually, static methods are used to implement functions that belong to the class, but not to any particular object of it.

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!