r/learnjavascript • • Oct 10 '20

call(), apply() and bind() in JavaScript explained. In this post you will learn about the three function methods in JavaScript; call(), apply() & bind(). They are very useful methods to learn and one should know about them to make their life easy.

https://sachinkoli.com/call-apply-and-bind-in-javascript-explained
129 Upvotes

12 comments sorted by

48

u/inabahare Oct 10 '20

Oh dear The bloggers finally found three functions that aren't map filter and reduce

2

u/tapu_buoy Oct 10 '20

well these are anyways the other three functions for such bloggers. :D

22

u/armastevs Oct 10 '20

I never really use these functions in real life, but yet they are constantly asked in job interviews. Our industry is so weird.

13

u/akerson Oct 10 '20

my problem with these tutorials is I don't think the functions are difficult to understand, it's that I don't practically know when to use or care about them. You can make as many names and address and favorite animal tutorials as you want, I still don't see the benefit in not just making the function inherent to the object.

1

u/inabahare Oct 11 '20

it's that I don't practically know when to use or care about them

another thing that's a bane of like 90% of tutorials (and maybe even education) in this field is the fact that they're sooooo happy to tell you what something is but when it comes to showing how you actually use it, they just kinda skip it

6

u/Joghobs Oct 10 '20

I only ever see then used when looking through the guts of popular frameworks and libraries.

2

u/Morphray Oct 11 '20

In the rare case I use these in real life I consider it a failure on my part to properly structure the code. The concepts behind these are important, but I would avoid them if at all possible.

1

u/[deleted] Mar 24 '21

I was just asked today in a preliminary phone call with a recruiter the difference between call and apply and I didn't know how to answer. Do I need to brush up on some basics or is this just a weird question that isn't really relevant?

1

u/armastevs Mar 24 '21

Call and apply are only relevant for job interview questions 99% of the time

1

u/straightouttaireland Oct 10 '20

You would use bind in Class components in React but that's about it really

5

u/LEDThereBeLight Oct 10 '20

Are call and apply at all useful anymore? I have literally never used either one. I’ve only used bind in react classes.

2

u/[deleted] Oct 11 '20

Can you give some exercises based on CBA, recursion, closures and promises? I learned all these concepts but don't know what to do with this I want to understand it clearly