illustration for Composing Closures and Callbacks in JavaScript
pro

Composing Closures and Callbacks in JavaScript

Instructor

John Lindquist

4h 20m closed-captioning
·
69 lessons
Published 4 years ago
|
Updated 4 years ago

As a developer, you'll often make use of APIs that have you pass in a callback function. For example, adding event listeners or using various other DOM or Node APIs.

What's less common is writing your own code that makes use of callbacks. Many developers know what a callback is, but not the why or how of implementing them in their projects.

A callback is a function that you pass to another function, so that the function that you pass it to controls the invocation of that function.

To help keep things straight, John Lindquist calls the innermost callback the Listener, and the function it gets passed into the Broadcaster.

Think of it as one function broadcasting values to another function that is listening for them.

These Broadcaster-Listener callback relationships can be composed to solve problems in the realm of timing, buffering, and caching.

This pattern of composing callbacks is the foundation of RxJS and other libraries that handle complex async scenarios.

In this course, John Lindquist guides you from a blank JavaScript file all the way through creating a library of reusable functions not unlike those found in RxJS. The difference is you'll be writing from scratch.

You'll learn techniques for solving Callback Hell with composition, implementing debouncing, and building a word game among several other examples.

Using callbacks in code is a major pattern in JavaScript, and learning to work with them effectively will take your problem-solving skills to the next level.

Listen to John Lindquist tell you about this course:

What you'll learn:

  • Closures, Callbacks, and Composition
  • Currying, Caching, and Creating operators
  • Creating custom React Hooks

Modules

4h 20m • 69 lessons • 8

    You might also like these resources:

    illustration for Just Enough Functional Programming in JavaScript
    Kyle Shevlin・30m・Course

    Functional programming is a useful evergreen skill that will travel with you for your entire career. This course dives into the fundamentals of functional programming in JavaScript to give you a working vocabulary and patterns you can apply on the job today.

    illustration for Advanced JavaScript Foundations
    Tyler Clark・41m・Course

    This course is perfect for the advanced beginner that is fluent in core JavaScript and is ready to take it to the next level of expertise.

    illustration for JavaScript Promises in Depth
    Marius Schulz・1h 7m・Course

    Promises are one of the core building blocks of modern JavaScript applications. We rely heavily on asynchronous operations and have a lot of our tools at our disposal to make those operations more efficient and simpler to think about.