function forcall(fun) {
console.log(fun)
return function f1(...args) {
console.log(11, args)
if (args.length >= fun.length) {
return fun(...args)
} else {
return (...moreargs) => {
console.log(22, moreargs)
const newargs = args.concat(moreargs)//[...args, ...moreargs]
return f1(...newargs)
}
}
}
}
function add(a, b, c) {
return a + b + c;
}
const aa = forcall(add)
const ret = aa(2)(4)(3)
console.log(ret)
function debounce(fun, duration = 500) {
let timerId;
return function (...args) {
clearTimeout(timerId)
timerId = setTimeout(() => {
fun.apply(this, args)
}, duration);
}
}
function add(a, b) {
console.log(a + b)
}
const fun1 = debounce(add, 3000)
fun1(2, 3)