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

106
Visualizações
pass value from object to another object in javascript

const small = {
  a: 1,
  func: function(b, c, d) {
    return this.a + b + c + d;
  },
};

const large = {
  a: 5,
};

small.func(2, 3, 5);

I need to access a: 5 from large object into small object. currently small.func(2,3,5) is giving 11 as output. I need to get 15 as ouput.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can either use call or apply here as:

const result = small.func.call(large, 2, 3, 5);

What above statement means is that You are taking the function(or can say borrowing) small.func function and applying in the context of large object with argument 2, 3, 5.

const small = {
  a: 1,
  func: function(b, c, d) {
    return this.a + b + c + d;
  },
};

const large = {
  a: 5,
};

   const result = small.func.call(large, 2, 3, 5);
// const result = small.func.apply(large, [2, 3, 5]);
console.log(result);

about 4 years ago · Juan Pablo Isaza Relatório

0

Like this-

function func(b, c, d) {
    return this.a + b + c + d;
  }
const small = {
  a: 1,
  
};

const large = {
  a: 5,
};

func.call(large, 2,3, 5)
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