I have the following situation where I have a function f
which takes an argument input
.
I want to be able to have f
such that
f()
can not return fo
, it has to return a function. To get fo
you need to call f like f()('')
.
Try this:
function f(input, acc) {
acc = acc || 'f'
if (input === undefined) {
return function(a) {
return f(a, acc + 'o')
}
}
return acc + input
}
console.log(f('l'))
console.log(f()(''))
console.log(f()('l'))
console.log(f()()('foo'))