Two sets of parentheses after function call Ask Question

Two sets of parentheses after function call Ask Question

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

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

これは何を意味し、JavaScript でどのように処理するのでしょうか?

ベストアンサー1

これは、最初の関数 ( $filter) が別の関数を返し、返された関数がすぐに呼び出されることを意味します。例:

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

var addTwo = add(2);

addTwo(4) === 6; // true
add(3)(4) === 7; // true

おすすめ記事