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

137
Vistas
What difference does it make of accessing through "Object" and through Object.constructor?

I have the following code:

    var obj2 = new Object();
    
    console.log(Object.isExtensible(obj2)); //returns 'true'
    console.log(obj2.constructor.isExtensible()); //returns 'false'

Could anyone explain why the first console print returns boolean 'true' and the second one 'false' and what difference it makes if isExtensible() is called either way.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The .constructor of an instance refers to the class / function that instantiates an instance. Since you're doing

var obj2 = new Object();

this means that obj2.constructor is the same as Object.

So

obj2.constructor.isExtensible()

is calling Object.isExtensible, but without an argument. isExtensible requires an argument. If you pass it the obj2, it'll do what you expect:

var obj2 = new Object();

console.log(Object.isExtensible(obj2)); //returns 'true'
console.log(obj2.constructor.isExtensible(obj2));
console.log(obj2.constructor === Object);

But that's still confusing. I'd recommend never using obj2.constructor - just use Object instead, it'll make more sense.

Usually, you'd probably only want to use the .constructor property when you don't already have a reference to the class - otherwise, it's easier to just reference the class.

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