Home > Article > Web Front-end > Why Do We Use Double Parentheses in Function Calls in TypeScript and JavaScript?
Function Call with Multiple Parentheses in TypeScript and JavaScript
In AngularJS, filters are commonly used to format data in views. When using filters, developers often notice that they need to specify two sets of parentheses after the function call.
$filter('number')(number[, fractionSize])
Meaning of Double Parentheses
The double parentheses indicate that the first function ($filter) returns another function, and the returned function is immediately called with the specified arguments. This pattern is known as currying.
How to Handle It
In JavaScript, this pattern can be implemented using anonymous functions:
function add(x) { return function(y) { return x + y; }; } // Create a function that adds 2 to any number var addTwo = add(2); // Use the addTwo function addTwo(4) === 6; // true
In this example, the add function returns a function that accepts another parameter y. When we call addTwo(4), the returned function is executed with 2 and 4 as arguments, resulting in 6.
The above is the detailed content of Why Do We Use Double Parentheses in Function Calls in TypeScript and JavaScript?. For more information, please follow other related articles on the PHP Chinese website!