end video

This lesson is only accessible in the paid version of the course.

Get access to all lessons 💫 price: 34.99$

If you already have an account click here.

§ How to do partial application in JavaScript

In this video, we will learn about partial application in JavaScript and how it allows you to create new functions by partially applying arguments to existing functions. We will explore how partial application can be used to create reusable utility functions and simplify complex function compositions.

Partial application is a technique in functional programming that allows you to create a new function with some of the arguments pre-filled. This can be useful when you want to reuse a function with the same arguments multiple times.

Here is an example of partial application in JavaScript:

function add(a, b) {
  return a + b;
}

let add5 = add.bind(null, 5);
console.log(add5(3)); // Output: 8
console.log(add5(4)); // Output: 9

In this example, the add5 function is created by partially applying the add function with the argument 5. This means that the add5 function is equivalent to calling add with the first argument fixed to 5. The add5 function is now a new function that takes one argument and returns the result of adding 5 to it.

Partial application can be useful when you want to reuse a function with the same arguments multiple times. It is a technique that is often used in functional programming. In Javascript, the most common way to implement it is by using bind method. It allows to create a new function with some of the arguments pre-filled.

questionnaire

Practice

Practice is the fastest way to learn knowledge permanently. I have prepared a small task for you related to the lesson.

Practice
discussion

Materials

Materials related to the lesson:
Files associated with the lesson

Materials

Next: Dependency injection(14:32)

To the lesson →