Two sets of parentheses after function call

前端 未结 3 1409
暖寄归人
暖寄归人 2020-11-22 07:16

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

$filter(\'number\')(number[, fractionSize])
3条回答
  •  攒了一身酷
    2020-11-22 07:46

    $filter('number') returns a function that accepts two arguments, the first being required (a number) and the second one being optional (the fraction size).

    It's possible to immediately call the returned function:

    $filter('number')('123')
    

    Alternatively, you may keep the returned function for future use:

    var numberFilter = $filter('number');
    
    numberFilter('123')
    

提交回复
热议问题