Create a new function that pre-fill in an argument to another function.
Use it like this:
// a function that generates a new function for adding numbers
function addGenerator(num) {
return function(toAdd) {
return num + toAdd;
}
}
// using above, make this function
var addFive = addGenerator(5);
alert(addFive(4) == 9);
.
No comments:
Post a Comment