Skip to content
Advertisement

Two sets of parentheses after function call

I was looking how filters works in Angularjs and I saw that we need to send 2 sets of parentheses.

$filter('number')(number[, fractionSize])

What does it means and how do we handle it with JavaScript?

Advertisement

Answer

It means that the first function ($filter) returns another function and then that returned function is called immediately. For Example:

function add(x){
  return function(y){
    return x + y;
  };
}

var addTwo = add(2);

addTwo(4) === 6; // true
add(3)(4) === 7; // true
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement