【发布时间】:2023-03-11 02:11:02
【问题描述】:
我对 JS bind、apply 和 this 有点困惑。
问题
- 为什么
this和null在下面的 sn-p 中可以互换? - 以下上下文中的
this是否指向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'
【问题讨论】:
标签: javascript currying