Reading through eloquent javascript in an attempt to wrap my head around functions, I read this example code:
function makeAddFunction(amount) {
function add(number) {
return number + amount;
}
return add;
}
var addTwo = makeAddFunction(2);
var addFive = makeAddFunction(5);
show(addTwo(1) + addFive(1));
I get the gist of it, but having examined the code and read the accompanying text several times over a few hours, this just hasn't clicked for me: What exacly is this code doing? Where does the add
function acquire the number
parameter? Does it come from the show
command? If so, how does it get passed around? I just don't see it...