This video discusses partial application in JavaScript, and how it's used to delay the execution of a function until all the arguments are collected. We give a simple example using our "add" function, and create a partial application function to fix the first argument.
- [Narrator] First we'll talk about partial application.…Now what partial application is is this.…Let's say that we have a function…with a certain number of arguments.…What partial application is is taking one…of those arguments and fixing the value.…This gives us a function with one less argument.…We can then call this function and it will call…our original function with both the argument…that we fixed and the new argument that we pass in.…Let's change this example around a little bit…so that we can get a better idea of how this works.…
So, what if instead of having an add function that takes…only two arguments, we had one that took three?…If we wanted to partially apply only the first argument,…we could change it like this.…Notice that now when we call partiallyApply,…we get a function that takes two arguments.…These two arguments represent the last two arguments…of our add function.…Now we can call add5 with another argument.…
Notice that this gives us exactly the same result…as if we had simply called add…
Released
7/14/2017- What's functional programming?
- Functional vs. object-oriented programming
- First-class functions
- Higher-order functions
- Array functions
- Mapping, filtering, and reducing
- Simple callbacks
- Callbacks with arguments
Share this video
Embed this video
Video: Partial application