What does the second set of parentheses after require in Node.js mean?
This syntax you are seeing is called Function currying , which is a popular technique when writing compositional functions in the functional programming paradigm. Currying and functional programming aren't new concepts, they've been around for decades, but functional programming is starting to get very popular in the JavaScript community.
Currying basically allows you to immediately call a function call from a function that returns a function.
Consider this function, which returns a function:
function foo(x) {
console.log(x);
return function(y) {
console.log(y);
}
}
now when you call this function you can do the following:
foo(1)(2);
which will output to the console:
1 2
So, in the example you posted, the function clean()
should return a function that takes two parameters, for example:
function clean(a) {
return function(b, c) {
console.log(a, b, c);
}
}
which allows you to call it like this:
clean('foo')('bar', 'baz');
//=> 'foo' 'bar' 'baz'
This was a super basic example, but I hope it helps!
source to share