Javascript:What is meaning of sum(2)(3) //returns 5;
问题 Here is code blow to return it's value. function sum(a){ return function(b){ return a+b; } } sum(2)(3); It returns 5 but if I type code: function sum(a){ function add(b){ return a+b; } return add(b); } It doesn't return expected value 5. I don't even understand how sum(2)(3) calls function. Any explanation for this is very much appreciated. 回答1: This is called a closure. sum(a) returns a function that takes one parameter, b , and adds it to a . Think of it like this: sum(2)(3); // Is