From the course: Learning ECMAScript 6+ (ES6+)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Working with generators - JavaScript Tutorial
From the course: Learning ECMAScript 6+ (ES6+)
Working with generators
- [Instructor] Generators are a new type of function that allow us to pause functions in the middle of execution to be resumed later. You know you're looking at a generator when you see an asterisk immediately following the function keyword. So let's go ahead and create a generator here. We're going to create a generator called director. So the director generator function is going to do a countdown for us, basically. Within a generator, we can hit pause by using the yield keyword, and this can be used numerous times within the same function. Now, inside of the director function, we're going to use four yield statements for a director counting down until the camera is rolling. Now, let's set a variable that calls the director function. And what we'll do here is we'll console.log to retrieve the values from the director generator. So if I call this method called .next, the next function is going to return an object that…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.