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

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

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