Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda