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

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

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