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

232
Views
What does invoking call method inside another constructor function do?

I have two constructor functions here: Car and Van

    var Car = function (location) {
        this.loc = location
    };

    Car.prototype.move = function () {
        this.loc++
    }

    var Van = function (location) {
      Car.call(this, location)
    }

Could you tell me what this line Car.call(this, location) is doing? My assumption is that we want to inherit the loc property from the Car class to the Van class.

My confusion is on what now this inside

    Car.call(this, location)

is referring to? and also what this inside Car

    var Car = function (location) {
        this.loc = location
    };

is referring to? Can someone provide any insight?

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

0

Car.call(this, location)

this will associate the .loc property to the Van object. this here refers to the Van. If you instantiate Van, it will associate the same

var v = new Van(1); // v.loc=1
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!