Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda