In this exercise, you must use closure to define a foo() function that returns a function. This returned function remembers only the first two arguments that were passed to foo() and always adds them together.
- Pull exercise two up with me.…Again, pull up the readme and the ex2.js.…I'll go ahead and close exercise one,…since we're not using that anymore, let's look…at the readme for exercise two, it says define foo…so that it produces a function, we've already seen that,…and that function needs to remember only the first…two arguments that were passed to foo,…and then the function that we've returned back…it needs to always add those two together.…Parse through that readme,…make sure you fully understand what it's asking for.…
Here's the setup.…I should be able to make a function called x…that's already remembering the three and the four…and every time I call x, I'm going to get seven oh.…Not very many lines of code but let's make sure…you have your brains wrapped around…how we can use closure, okay?…
This course was created by Frontend Masters. It was originally released on 03/08/2016. We're pleased to host this training in our library.
- Pure functions
- Manual composition
- Composition utility
- List operations
Skill Level Intermediate
1. Pure Functions
2. Composition and Immutability
3. Closure and Recursion
4. List Operations
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.