declare a function:
1 2 3 |
function sayHello(name, message, extra) { return name + ', ' + message + extra; } |
we give our function to partialRight, along with
the parameter that goes on the right side.
1 |
var sayGoodMorningTo = partialRight(sayHello, 'Good Morning', '!'); |
Then use the partial function:
1 |
sayGoodMorningTo('Ricky'); |
Ricky, Good Morning!
Notice we gave two parameters in the partialRight. This means we already decided that other two parameters (message, extra) have already been dictated when we call partialRight.
Therefore, we have already decided that when using the partial function, we only take ONE parameter (name).
Of course we can change this to only providing the third parameter, and having the user provide two parameters for the partial function.
1 2 |
var sayGoodMorningTo = partialRight(sayHello, '???'); sayGoodMorningTo('ricky', 'Good Morning'); |
ricky, Good Morning???