函数调用后的两组括号 [英] Two sets of parentheses after function call
本文介绍了函数调用后的两组括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究 过滤器 在 Angularjs 中的工作原理,我发现我们需要发送2组括号.
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 处理它?
What does it means and how do we handle it with JavaScript?
推荐答案
这意味着第一个函数 ($filter
) 返回另一个函数,然后立即调用返回的函数.例如:
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
这篇关于函数调用后的两组括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文