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

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

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