Check out a free preview of the full Interviewing for Front-End Engineers course

The "JavaScript Scope: bind Exercise" Lesson is part of the full, Interviewing for Front-End Engineers course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to work on the bind exercise. Jem also talks about scope being the context in which we operate in, and briefly covers 3 common elements used to change scope.

Preview
Close

Transcript from the "JavaScript Scope: bind Exercise" Lesson

[00:00:00]
>> As earlier we discussed scope is essentially the context that you're operating in, the things that are available to you. And when we think about scope, we generally wanna know what are the ways to change the scope. Because implicit scope, that's fine. If you run a function, it's gonna be in the module scope or the window scope, things like that.

[00:00:18]
But if I wanna change that because I'm referencing this variable or anything like that, that's something we do as engineers sometimes when we need to. Particularly in react if we need to bind, we say bind this to change the scope, things like that. But the three main ways we change scope our call, what's call take?

[00:00:39]
A bunch of elements, right? Yes. Good answer. Apply takes does same thing, but it takes an array. And then bind is a way of doing partial application. So we change the scope without actually calling the function itself. In this one we're returning the function. These other two will return or will actually execute the function itself.

[00:00:59]
Whereas bind says, here's the new scope, but we'll execute it later. I use bind for partial application because you can say bind this and apply a bunch of parameters. And then now those will be implicitly past whenever you execute that function. I know, if I'm talking a little bit like what is partial application?

[00:01:17]
I would Google it. It's actually a pretty useful tool once you understand it. But I'm not gonna ask you to code that up because that's not fair. I don't think that's a relevant question. But what I do think is a relevant question is implementing bind. So what I want you to do today is I want you to implement function prototype bind.

[00:01:37]
And I'll give you a hint cuz this one is a little trickier, the solution is not long. But you're gonna need one of those methods we just talked about earlier that is in bind.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now