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

160
Vistas
How Prototypal inheritance works in reverse order

As you can see below is my code. I have created two objects halogen and balloon and given halogen property of sing and balloon property of read. I am calling halogen.read() it is getting read property but halogen is prototype for balloon but balloon is not prototype of halogen. How js is working under the hood??

const halogen = {
  sing: function() {
    console.log('I can sing');
  }
}

const balloon = new Object(halogen);

balloon.read = function() {
  console.log('I can read');
}

halogen.read();

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

0

When you call the Object constructor with an argument that isn't null or undefined, it doesn't create a new object (not even when you use new, surprisingly; spec link), it just converts the argument to object if it isn't already an object and returns it. Since halogen already refers to an object, there's no conversion required and you're basically doing balloon = halogen and they both end up referring to the same object.

You probably meant to use Object.create, which creates a new object and assigns the object argument you provide as the new object's prototype:

const halogen = {
    sing: function() {
        console.log("I can sing");
    },
};

const balloon = Object.create(halogen);

balloon.read = function() {
    console.log("I can read");
};

console.log(typeof halogen.read); // undefined
console.log(typeof balloon.read); // function
console.log(typeof balloon.sing); // function

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