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

169
Visualizações
JavaScript Bind, Apply, and the `this` pointer

I got a little confused with JS bind, apply, and this.

Questions

  • Why are this and null interchangeable in the following snippet?
  • Does this in the following context point to the window?

function curry(fn) {
  // your code here
  return function curryInner(...args) {
    if (args.length >= fn.length) return fn.apply(this, args);
    return curryInner.bind(this, ...args);  //change this to null, still pass the test
  };
  
}
const join = (a, b, c) => {
   return `${a}_${b}_${c}`
}

const curriedJoin = curry(join)

console.log(curriedJoin(1, 2, 3)) // '1_2_3'

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

No, this points to the this context of the function it is in.

In this case, it really doesn't matter what you put there since the only purpose of calling bind is to create a copy of the function with the args already set.

return curryInner.bind(null, ...args)

could essentially be replaced with

return function() {
  return curryInner(args);
}
about 4 years ago · Santiago Trujillo 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