Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!