I got a little confused with JS bind
, apply
, and this
.
Questions
- Why are
this
andnull
interchangeable in the following snippet? - Does
this
in the following context point to thewindow
?
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'