Search⌘ K
AI Features

Apply, Call, Bind, & arguments

Explore how to explicitly set the this value in functions using apply, call, and bind methods. Understand working with the arguments object and converting it to arrays. This lesson strengthens your grasp of JavaScript's object-oriented features and prepares you to use these methods effectively in writing clean, reusable code.

We are going to showcase a way to explicitly set the value of this in a function. We can use the apply, call, and bind methods. These are simple methods, but crucial to understanding how to read code and write proper object oriented JavaScript.

Occasionally, it’s more useful and makes more sense for the this value to be some other object than what JavaScript wants to set it to. We can override some of the automatic cases of this inside functions by using these three methods.

Occasionally, we want to use a method of one object on another. Remember that in OOP, methods are meant to act on the object that they are a property of. It’s often useful to take these methods and apply them (no pun intended) to different objects to perform the same action. ...