Who the hell is this function
We’ve learned about functions and arguments, it's time to meet the callback.
Who the hell is this callback
In our example, person number one takes the name of person number two (1) and calls him inside of his task (2). So person number two is a callback function.
Functions are still called functions. But if they are accepted as arguments in other functions, they are also called callback functions. Now you know who is hidden under the name callback. And who is the king. Or think he is.
In the end...
And if you like this article you need to know that every Monday, I send a letter to 4,000+ Web Developers with 3 hand-picked articles from the tech world, 2 web development guides, and 1 best Tweet of the week
“Your newsletter is fking awesome, really Nick. It gives me a great start to the week with a lot of insightful knowledge.”
Join smart developers who get short and full of knowledge letters.
Top comments (1)
There's a book mail-order company with pretty old systems.
You send a letter (snail-mail) to them saying which book you want to buy, and they send you back a letter saying when to come to the warehouse and pick it up (only pickups are allowed, they aren't really set up to send books by courier yet).
But they do give you one other option, which goes like this:
When sending them your letter saying which book you want, you're allowed to slip a phone into the envelope too.
When the book is ready, they'll power up the phone, find the app called "book-callback", and open it, and type some details about the book.
So to have your book sent to you, write a little app called "book-callback" that can book a courier to send something to your house, put your app on a cheapo phone, and send that in the envelope.
So, even though the book company doesn't know anything about couriers (or even where you live), you still get your book in the post.
A callback in programming is like that phone. It's a bit of your own code you can send in a request. The one doing the work doesn't need to know how to it all, just how to kick off your callback. Your code takes it from there.