Day 65 JavaScript Call() Apply() Bind()

Hello coders it’s been a busy weekend. I’ve been doing the same habits as last week. The habits were listening to the JavaScript course and using the Grasshopper app to practice code, which I’ve completed fundamentals II.

Onto to call,apply, and bind. All three of these functions are already within every function created automatically. They are all associated with the this function.

.Bind creates a copy of whatever function you’re calling on. Whatever method you pass to this object or whatever object you pass to this method it points to by reference. It does not execute the function.

.Call executes a function and decides what the this variable should be and the rest is just parameters that would normally pass to the function.

.Apply is the same as .bind however its parameters are in brackets because it needs to be in an array. That is the only difference from .apply and .bind.

The benefits of copying functions with apply and bind is that it literally borrows functions from other functions. Hence called borrowing functions.

Another benefit of bind is that it does something called function currying. Function currying copies a function but with preset parameters. It’s copies a function and sets a parameter like a const variable but with functions. You can stack permanent parameters is the benefit.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Up ↑

%d bloggers like this: