The bind Method | JavaScript 🔥 | Lecture 125

The Coding Classroom
28 Apr 202321:33

Summary

TLDRThis video tutorial delves into JavaScript's bind method, which, unlike the call method, does not immediately invoke a function but returns a new function with 'this' keyword bound to a specified value. Using an airline booking example, it demonstrates how bind can simplify repetitive function calls by presetting 'this' to Eurowings, enabling easy flight bookings across different airlines. The video further explores partial application, showing how bind can predefine certain arguments for functions, such as specific flight numbers, thereby simplifying the function's usage. Additionally, it touches on the use of bind with event listeners and introduces the concept of creating functions that return other functions for advanced use cases.

Takeaways

  • 🔑 The bind() method allows you to set the 'this' keyword for a function and returns a new function with that 'this' value bound.
  • ➡️ Unlike call(), bind() does not immediately invoke the function; instead, it returns a new function with 'this' bound to the provided value.
  • 🛫 bind() can be used to create function shortcuts for specific objects, like bookEW for Eurowings airline.
  • 📋 With bind(), you can also pre-set arguments for a function, a technique known as 'partial application'.
  • ⚡ bind() is especially useful when working with event listeners, where 'this' refers to the element the listener is attached to.
  • 🔄 By binding the correct 'this' value, you can ensure methods have the intended context when called in event listeners.
  • 🧩 Partial application allows you to create specialized functions from more general ones by pre-setting some arguments.
  • 🏭 bind() can be used for partial application even when you don't care about the 'this' value (by passing null).
  • 🔄 Returning a function from another function is an alternative technique to achieve partial application without using bind().
  • 🚀 Mastering bind() and partial application unlocks powerful ways to create specialized, context-aware functions in JavaScript.

Q & A

  • What is the main difference between the bind and call methods in JavaScript?

    -The main difference is that the call method immediately invokes the function with a specified this value and arguments, while the bind method returns a new function with a predefined this value and can include predefined arguments.

  • What is the purpose of using the bind method in JavaScript?

    -The bind method is used to create a new function where the this keyword is set to a specific value, and it can also predefine arguments for the function. This is useful for setting the context of 'this' and for partial application of function parameters.

  • How does the bind method work with arguments in JavaScript?

    -The bind method allows you to not only set the this value but also to preset arguments for the function. These preset arguments are fixed when the new function is created, and the function will always be called with these arguments.

  • Can you explain partial application with an example from the script?

    -Partial application is when some arguments of a function are preset. For example, creating a bookEW23 function that is a specific instance of a book function with the flight number 23 preset. This results in a new function that only requires the passenger name as an argument.

  • Why does the script use bind in the context of an event listener?

    -The script uses bind in an event listener to set the this keyword to a specific object (Lufthansa in the example) instead of the default this value (the button element), ensuring the function uses the correct context when invoked as an event handler.

  • How is the bind method used to solve the 'this' keyword issue in event listeners?

    -Bind is used to return a new function with the this keyword set to the desired object. In event listeners, this ensures the function called as the event handler references the correct object instead of the DOM element that triggered the event.

  • What is the significance of null in the addTax.bind call in the script?

    -Null is used as the first argument in the addTax.bind call because the function does not use the this keyword. It's a convention to pass null when the this value is irrelevant, allowing the focus to be on presetting the subsequent arguments.

  • How does the script demonstrate the use of bind for simplifying repetitive tasks?

    -The script shows that by using bind to create new functions with preset parameters, such as airline or flight number, repetitive tasks like booking for specific flights or airlines can be simplified, avoiding the need to repeatedly set these parameters.

  • What is the concept of partial application as demonstrated in the script?

    -Partial application, as demonstrated, involves creating a new function by presetting some of the original function's arguments, such as setting the flight number or tax rate in advance. This results in a function that requires fewer arguments in future calls.

  • How does the script illustrate the flexibility and power of the bind method in function customization?

    -The script illustrates the flexibility and power of bind by showing how it can create more specific versions of a general function through partial application, such as presetting the flight number or tax rate, making the function simpler and tailored for specific uses.

Outlines

00:00

🔍 Exploring the Bind Method and Partial Application

This paragraph introduces the bind method, which allows manually setting the 'this' keyword for a function call. Unlike call, bind does not immediately call the function but returns a new function with the 'this' keyword bound. The paragraph demonstrates using bind to create airline booking functions with preset 'this' values. It further explores partial application, where arguments can be preset in the bind method, simplifying subsequent function calls.

05:01

🖱️ Using Bind with Event Listeners

This paragraph explains how the 'this' keyword in an event handler function points to the element the handler is attached to, causing issues when accessing object properties/methods. It demonstrates using bind to manually set the 'this' keyword to the desired object, ensuring correct behavior when handling events on DOM elements bound to object methods.

10:03

💰 Calculating Tax with Partial Application

This paragraph introduces a use case for partial application with the bind method, unrelated to the 'this' keyword. It creates a general function to calculate tax on a value and then uses bind to create a new function with the tax rate preset, simplifying subsequent calculations for that specific rate.

15:04

🎯 Implementing Partial Application Without Bind

This paragraph challenges the viewer to reimplement the tax calculation example from the previous paragraph using the technique of one function returning another function, instead of relying on bind. It provides a solution demonstrating how to create a higher-order function that returns a new function with the tax rate preset.

20:09

📋 Concluding Remarks

The final paragraph concludes the discussion on the bind method and partial application, acknowledging the advanced nature of the concepts covered. It also mentions an upcoming coding challenge related to the topics discussed in this section.

Mindmap

Keywords

💡bind()

The bind() method is a function in JavaScript that creates a new function with a bound `this` value and optionally prebounded arguments. Unlike the call() and apply() methods which execute the function immediately, bind() returns a new function that can be executed later with a specific `this` context and arguments. In the video, bind() is demonstrated with examples like creating bookEW23 function that is prebounded to the Eurowings object and the flight number 23.

💡this keyword

The `this` keyword in JavaScript refers to the object that the current function is a property of. Its value is determined by the execution context and how the function is called. In the video, the importance of correctly setting the `this` value is highlighted, especially when dealing with event handlers where `this` refers to the element the event is bound to instead of the expected object context. Methods like call(), apply(), and bind() are used to explicitly set the `this` value.

💡Partial Application

Partial application is the technique of creating a new function by applying some of the arguments to an existing function, producing a new function of a smaller arity. In the video, this concept is illustrated using the bind() method to create a new addVAT function that is prebounded with a specific tax rate, allowing it to calculate the tax for any given value without needing to pass the rate every time.

💡Higher-Order Functions

Higher-order functions are functions that operate on other functions, either by taking them as arguments or by returning them. In the video, addEventListener is used as a higher-order function that takes a callback function (the event handler) as an argument. The bind() method is also demonstrated as a way to create new functions based on existing ones.

💡Callbacks

A callback function is a function passed as an argument to another function, to be executed after some operation has been completed. In the video, the event handler function passed to addEventListener is a callback function that will be called when the specified event occurs (in this case, a click event on a button).

💡Event Handlers

Event handlers are functions that are executed when a specific event occurs, usually in response to user interactions like clicks, key presses, or form submissions. In the video, an event handler function is attached to a button element using addEventListener, allowing the function to be executed when the button is clicked.

💡Arrow Functions

Arrow functions, introduced in ES6, are a concise syntax for writing function expressions in JavaScript. They have a shorter syntax compared to regular functions and lexically bind the `this` value, meaning that the `this` value inside an arrow function is determined by the surrounding lexical scope. In the video, an arrow function is used to define the addTax function.

💡Closures

A closure is a function that has access to variables in an outer (enclosing) function's scope, even after the outer function has finished executing. In the video, the concept of closures is demonstrated when creating the addTaxRate function, which returns a new function that "closes over" the rate variable from the outer function's scope.

💡First-Class Functions

In JavaScript, functions are first-class citizens, meaning they can be treated like any other value – they can be assigned to variables, passed as arguments to other functions, and returned from functions. This concept is evident throughout the video, where functions are passed as arguments (e.g., addEventListener), returned from other functions (e.g., addTaxRate), and assigned to variables (e.g., bookEW).

💡Method Chaining

Method chaining is a technique in JavaScript where multiple method calls on an object can be chained together, with each method returning the object itself to allow the next method call. Although not explicitly demonstrated in the video, method chaining is a common pattern in JavaScript, especially when working with libraries and frameworks that follow a fluent API design.

Highlights

bind also allows us to manually set this keyword for any function call, but unlike call, it does not immediately call the function. Instead, it returns a new function where this keyword is bound to the value passed into bind.

By binding the book function to the Eurowings object, we create a new bookEW function that automatically has its this keyword set to Eurowings, simplifying function calls.

bind allows presetting some arguments, creating a partially applied function like bookEW23 that only needs the passenger name, as the flight number is preset.

Partial application, where some arguments are predefined, is a common pattern enabled by bind.

bind is useful when using objects with event listeners, as the this keyword inside the listener refers to the element the listener is attached to, not the object.

Using bind on the event listener function allows manually setting the this keyword to the desired object.

bind can be used for partial application even when the this keyword is not involved, by passing null as the first argument.

An example shows creating an addVAT function by binding the tax rate argument, resulting in a function that calculates VAT for any value passed.

The order of arguments in bind is important when partially applying arguments.

Partial application using bind creates a new, more specific function based on a general function, differing from default parameters.

A challenge asks to rewrite the addVAT example without using bind, by having one function return another function.

The solution involves an outer addTaxRate function that takes the rate, and returns an inner function that takes the value and calculates tax.

This approach separates defining the rate from calculating the tax, similar to the bind implementation.

The transcript notes that this functional programming technique is advanced.

The transcript concludes by mentioning an upcoming coding challenge related to the section's content.

Transcripts

play00:01

So let's know, learn about the bind method.

play00:06

And just like the call method,

play00:08

bind also allows us to manually set this keywords

play00:12

for any function call.

play00:14

Now, the difference is that bind

play00:16

does not immediately call the function.

play00:19

Instead it returns a new function

play00:22

where this keyword is bound.

play00:24

So it's set to whatever value we pass into bind.

play00:29

So let's continue with our airline example

play00:32

from the previous lecture here.

play00:34

And now let's say that we need to use the book function

play00:37

for Eurowings all the time.

play00:41

So, remember we have this Eurowings object

play00:45

and then we used a book.call,

play00:48

to use the book function

play00:50

with Eurowings set to this keyword.

play00:54

So that's what we did in the last lecture.

play00:57

So let me just copy this code here.

play01:02

But now, as I said,

play01:03

we can use the bind method to create a new function

play01:08

with the this keyword also set to Eurowings, all right?

play01:14

So again, this will not call the book function.

play01:19

Instead it will return a new function

play01:21

where this keyword will always be set to Eurowings.

play01:26

And so let's create a new function here called bookEW,

play01:31

where its just a code of Eurowings.

play01:35

All right?

play01:37

And so now let's use this function.

play01:41

So bookEW, Steven Williams

play01:48

and we're missing the flight number here.

play01:51

So 23.

play01:54

And so as you see, this now looks

play01:56

like the normal book function call again.

play01:59

And that's because this function here

play02:01

already has the this keyword set in stone basically.

play02:05

And so here, of course, we no longer need to specify

play02:09

to these keywords again.

play02:11

So the signature here, so the name of the parameters

play02:15

is back to being simply the flight number

play02:18

and the passenger name, okay?

play02:22

And so now again, we see that Steven booked a seat

play02:25

on Eurowings flight EW23.

play02:28

And so that worked perfectly.

play02:31

Let's also of course, see at the object again.

play02:37

So with all the bookings and indeed here is Steven Williams

play02:42

in the flight that we just booked.

play02:45

Great, so this is really, really useful.

play02:48

And we could now of course go ahead and do the same

play02:51

for all the airlines.

play02:53

So creating one booking function for each of the airlines.

play02:57

And this then makes it a little bit easier

play02:59

to book a flight for each of the airlines,

play03:02

if we have to do it multiple times.

play03:05

So instead of having to use a call all the time,

play03:09

we can just do bind once.

play03:14

So defining the disk keyword once like this

play03:18

and from there on, we can always use these functions.

play03:27

.bind and this one, Swiss, all right?

play03:33

Now, I'm not gonna use them all here now

play03:35

because we already know how that works,

play03:38

all right?

play03:40

So this is great,

play03:41

but we can actually take this even further.

play03:44

So in the call method, we can pass multiple arguments here

play03:48

besides this keywords, right?

play03:51

And so in the bind method, we can actually do the same.

play03:54

And then all of these arguments

play03:56

will also be basically set in stone.

play03:59

So they will be defined

play04:00

and the function will then always be called

play04:03

with these same arguments.

play04:05

For example, we could use bind to create a function

play04:08

for one specific airline and a specific flight number.

play04:14

So let's say, bookEW, just like we had here,

play04:21

but then really specific, only for flight 23.

play04:25

So that would be book.bind

play04:30

and then of course we have to again, define Eurowings,

play04:33

but then we can start to finding the list of arguments

play04:37

or the list of parameters

play04:40

and setting the first one to 23, okay?

play04:47

And so if we look at our bind function now,

play04:50

remember that it needs the flight number and the name.

play04:54

But now in our bookEW23 function,

play04:57

it is as if this first argument was already set.

play05:01

And so all remaining function now only need the name.

play05:06

So this function,

play05:07

this one now only needs the name,

play05:10

because the number was already preset here

play05:13

in the bind method.

play05:15

So, let's see.

play05:18

So, our newly created function bookEW23,

play05:23

and let's now book a flight for myself.

play05:32

And let's book a flight for Martha,

play05:34

let's say, Cooper.

play05:37

And, yeah, let's check out our output here.

play05:42

And so these are the two.

play05:45

And indeed both of them are for Eurowings flight EW23,

play05:50

all right?

play05:51

And so that's exactly what we were expecting.

play05:54

Again, because we preset that 23 right here.

play05:58

If we preset this here

play05:59

to one, two, three, four, five,

play06:01

then of course, both of these new flights here

play06:05

would be booked onto that flight number, okay?

play06:11

So this allows us to set in stone, certain arguments.

play06:14

And so this function, the resulting function,

play06:17

then becomes even simpler.

play06:19

So right now all we need to pass in

play06:22

is the passenger name, right?

play06:25

And then everything else basically happens automatically.

play06:28

And taking this even further,

play06:30

we could even define, have the passenger name here

play06:34

for example, like this.

play06:35

And then this function would always book a flight for Jonas

play06:39

on flight 23.

play06:41

But that would probably take it a little bit too far now.

play06:47

And I deleted the 23 here,

play06:51

of course, I didn't want that.

play06:54

So this is correct.

play06:56

And by the way, what we did here,

play06:58

so, basically specifying parts of the argument beforehand,

play07:03

is actually a common pattern called partial application.

play07:07

So essentially, partial application

play07:10

means that a part of the arguments

play07:12

of the original function are already applied,

play07:16

so which means, already set.

play07:18

And so that's exactly what the bookEW23 function is, right?

play07:24

It's essentially the book function

play07:26

but with 23 already predefined.

play07:30

Great.

play07:31

So, hopefully this was a nice example for you to understand

play07:35

the call apply and bind methods,

play07:39

but there are also other situations

play07:41

in which we can use the bind method

play07:43

and where it is very useful.

play07:45

And one example of that is when we use objects together

play07:49

with event listeners.

play07:51

So let's write that here actually,

play07:54

with event listeners.

play08:00

And so now this button here

play08:02

will finally come into play.

play08:03

And maybe you've been wondering about that.

play08:06

But let's start by adding a new property

play08:08

only to the Lufthansa object

play08:12

and let's set it to 300.

play08:15

So meaning that this company has 300 planes.

play08:19

And then we also add a new method

play08:22

only to the Lufthansa object,

play08:24

which is to buy a new plane.

play08:31

So function,

play08:33

and now what we want to do is, this.planes++.

play08:39

So essentially we want to add a new plane,

play08:41

whenever we click on this button.

play08:43

So eventually that's what we will want to do.

play08:47

And then let's also log this.planes to the console.

play08:52

And probably we should also log this keywords

play08:56

to the console as well.

play08:58

And now let's actually attach our event handler

play09:01

to this element,

play09:03

let's inspect it here, okay?

play09:06

It should need to go to elements.

play09:09

So, this is the button here

play09:12

and it has the class, buy.

play09:15

So document.queryselector.buy,

play09:20

addEventListener for click.

play09:24

And then the second argument,

play09:26

as you already know, is the handler function.

play09:30

So addEventListener here is the higher order function

play09:33

which receives a callback function.

play09:35

And so that should be lufthansa.buyPlane, all right?

play09:44

So essentially, this function here

play09:46

is what we want to happen,

play09:48

which again takes the current number of planes

play09:51

and increases it by one.

play09:55

So let's do that.

play09:58

And now as I click on this button, let's see what happens.

play10:03

And we get not a number here.

play10:06

So this .Planes is now not a number.

play10:10

And the reason for that is that this keyword

play10:13

is this button element, okay?

play10:17

And do you know why that is?

play10:19

Well, in one of the theory lectures,

play10:22

we learned that in an event handler function,

play10:24

that this keyword always points to the element

play10:28

on which that handler is attached to.

play10:32

So, this is the handler function, right?

play10:35

And so it is attached to this element,

play10:39

so to this button.

play10:40

And therefore, inside of the handler function

play10:43

or the event listener, it doesn't really matter.

play10:46

But inside of this function,

play10:48

this keyword will point to the button element.

play10:51

And so that's why this keyword here

play10:56

returns this button, okay?

play10:59

So here you have yet another proof

play11:02

that this keyword really is set dynamically.

play11:05

Because if we simply called a Lufthansa.buyPlane out here,

play11:12

then of course, this keyword would be Lufthansa,

play11:16

so this object, right?

play11:18

Because that's the object calling the function.

play11:21

But in this case it is of course,

play11:24

this event listener function calling this function.

play11:28

And so therefore, the button itself

play11:31

will then become this keyword, okay?

play11:35

Here we now see the results

play11:36

of calling this function out here.

play11:39

And so now we started with 300

play11:42

and it was increased just as we wanted it to be.

play11:45

So let's take this out here

play11:48

and let's go back to clicking here

play11:49

to see the result we had before.

play11:52

So that's this button.

play11:54

Now, of course, in this handler function here,

play11:57

we still need this keyword to point

play12:00

to the Lufthansa object itself, right?

play12:03

Otherwise this logic here will not work.

play12:06

So what this means is that we need to manually define

play12:10

to this keyword right here.

play12:12

So right here.

play12:15

Now, how should we do that?

play12:16

Should we use the call method or the bind method?

play12:21

Well, we need to pass in a function here

play12:23

and not to call it.

play12:25

And so we already know that the call method

play12:28

calls the function.

play12:29

And so that's not what we need.

play12:31

And so therefore, we use bind.

play12:34

Because we already know that bind

play12:35

is gonna return a new function.

play12:38

And so this keyword should be Lufthansa,

play12:41

and so that's exactly what we define, okay?

play12:45

And now as we click here we should see the Lufthansa object

play12:50

being this keywords.

play12:52

Indeed, and that's now exactly what we got here.

play12:56

So that's the result of this line of code.

play12:58

And so again, this now points to Lufthansa,

play13:02

because that's what we told JavaScript to do right here.

play13:06

And so indeed now the number of planes

play13:08

is increasing each time that we click on this button.

play13:13

Great, so we have our problem solved.

play13:15

And in fact, we will do this a couple more times

play13:19

throughout the course.

play13:20

So this one is an important one.

play13:22

And in general, the bind method

play13:24

is something you really need to understand, all right?

play13:28

Now, just one final example here,

play13:30

which is again, gonna be about partial application,

play13:34

because this is another big use case for the bind method.

play13:41

And in this case of partial application,

play13:44

many times we are not even interested in this keywords,

play13:48

but we still use bind for this, all right?

play13:50

Now, remember that partial application

play13:53

means that we can preset parameters, all right?

play13:58

So let's start by creating a general function

play14:00

which adds a tax to some value.

play14:07

So let's start with the tax rate and then the value itself.

play14:14

And let's write an arrow function here.

play14:17

And so this works by doing

play14:20

value + value * the tax rate, right?

play14:28

So imagine that the tax rate would be 10%

play14:32

and the value 100.

play14:34

And so adding the tax to 100 would be 110.

play14:38

Well, let's actually do 200 to make it a bit more clear.

play14:42

And of course we need to call the function here itself,

play14:47

okay?

play14:48

So now 10% of 200 is 20,

play14:52

and so the results should be 220 and that didn't work.

play14:57

And yeah, that's because we need to define this here

play15:00

as a decimal number here of course.

play15:04

So only then this rate here can make sense, okay?

play15:08

So 220 now.

play15:11

So this here is the general function for adding tax.

play15:16

But now let's say that there is one tax

play15:18

that we use all the time.

play15:19

And so let's create a function for that.

play15:24

So for example, here in Portugal,

play15:26

the VAT, which is value added tax, is 23%.

play15:32

And so we can now use the bind function

play15:34

on this function and preset the rate always,

play15:40

so that it always will be this 23%.

play15:43

And then we have a function

play15:45

which only calculates the VAT

play15:46

for whatever value we pass into it.

play15:50

So, addTax.bind

play15:54

and then the first argument of bind

play15:56

is this keywords, remember?

play15:59

But in this case, we don't care

play16:01

about the this keyword at all.

play16:02

It's not even here in the function.

play16:05

And so, we just say, null.

play16:07

It could be any other value

play16:09

because nothing will happen with it,

play16:11

but it's kind of a standard to just use null.

play16:14

And now we can set the rate here.

play16:18

So let's preset it to 23%,

play16:20

so 0.23, all right?

play16:23

And so this sets the rate value here in stone.

play16:28

So essentially, this would be the same

play16:29

as writing...

play16:33

Let's paste it here.

play16:34

So this must be, addVAT equals,

play16:38

and the rate is preset to 0.23.

play16:46

So this is essentially what our addVAT function

play16:49

now looks like, okay?

play16:53

So, because we already set 0.23 in stone.

play16:59

So, now we can start using that.

play17:03

So this should be 123 and it is.

play17:10

We can use anything we want now like 23

play17:14

and so on and so forth.

play17:17

So I hope this makes sense.

play17:20

When you want to do this yourself,

play17:21

just keep in mind that the order of the arguments then

play17:25

is important.

play17:26

If you want it to preset the rate,

play17:28

then it has to be the first argument in this function.

play17:31

Otherwise, this will not really work here, okay?

play17:37

Now you could argue that what we just did here

play17:40

could easily have been done with default parameters.

play17:44

But this is actually different,

play17:46

because this here is creating a brand new,

play17:49

simply, more specific function

play17:51

based on a more general function,

play17:53

which is the addTax function.

play17:56

And of course, the example here

play17:58

could be a lot more complex too, right?

play18:02

So this really is different

play18:04

because using binds,

play18:05

actually it really gives us a new function.

play18:08

So, it's as if we returned a new specific function

play18:13

from the addTax function.

play18:15

And actually now I have a nice challenge for you

play18:19

which is to essentially rewrite this whole example here,

play18:23

but using the technique of one function

play18:26

returning another function.

play18:28

So we have one lecture about that

play18:30

and maybe you can go back and take a look at that.

play18:32

And then I want you to essentially,

play18:34

create a function that can return a function

play18:37

which will do just what this one does.

play18:40

So that's probably really challenging.

play18:43

So don't beat yourself up if you cannot do it.

play18:46

I know it is a challenge,

play18:48

but you can still try to take a minute or two

play18:51

and, yeah, really try it.

play18:54

If you can't do it,

play18:55

then just watch the solution in a minute, okay?

play18:58

Just don't use bind of course,

play19:00

because with that we already have the solution.

play19:03

So use the technique that I showed you earlier

play19:05

with the grid function, remember?

play19:08

And so here you can do something similar.

play19:11

So, see you in a second with the solution.

play19:17

Alright.

play19:18

I hope you tried that out.

play19:21

And here is how I would have done it.

play19:23

So, the first function here,

play19:26

I'm gonna call it addTaxRate.

play19:31

And I could do this with the arrow functions,

play19:34

but then that looks really confusing.

play19:37

So let's just focus on the functionality here.

play19:40

So this is the first function which only receives the rate.

play19:43

So similar to what we did here.

play19:46

And then what it does is to return a new function.

play19:52

And then this new function

play19:53

is the one that takes in the value.

play19:57

And it will then return just as the other function,

play20:00

value + value * the rate, okay?

play20:08

And so now based on this one,

play20:11

we could create addVAT2.

play20:16

And so that would be, addTaxRate

play20:21

and then call it with 0.23.

play20:26

And then let's just do the same

play20:28

to see if the results are the same.

play20:31

So, VAT2, and two, give it a try and here you go.

play20:37

So the results are the same.

play20:39

And so this addVAT2 is the same function as this one.

play20:45

So just to recap, we created this function,

play20:48

which then returns this one.

play20:51

So the first one is the one that needs the rate,

play20:55

because the rate is also what we used

play20:57

to define this addVAT function here, right?

play21:02

And so the resulting function

play21:04

is then the one who takes in the value.

play21:06

And that's why we have value here in the inner function too.

play21:10

Now this is just another way of doing the same thing

play21:13

and this is already pretty advanced stuff really.

play21:17

So, absolutely don't be upset

play21:19

if you didn't do this by yourself.

play21:22

But anyway, in the next video

play21:23

we have coding challenge number one

play21:26

of this section coming up.

play21:27

And so I hope to see you there very soon.