Hey all! š Iām Ryo, a Sr. Design Technologist at PlayStation. I do web dev with React/TS/Node and game dev with Unity/C#/C++/OpenGL/DirectX. Feel free to ask me any questions! š¤
Callbacks are friends we send along inside functions to help accomplish additional tasks.
I'm going to send you to the store with money to get groceries. But I need to know how you're doing at the store. So I'm also going to send your friend, and he'll call back home and let me know how things are going. I might even ask him to do other things for me, like drive you home with the groceries.
functiongetGroceries(shoppingList,friend){this.purchase(shoppingList)if(friend){friend(this.purchase)}returnthis.purchase}functionfriend(purchase){console.log(`Hey mom, we bought everything. Here's the reciept`)console.log(purchase)}constshoppingList=['apples','carrots','chips']getGroceries(shoppingList,friend)
Sometimes, you need friends to do certain things, like setting a timeout (as exhibited by @nestedsoftware
). That's a 2-person job, someone to set the time and someone to actually do something.
Callbacks are friends we send along inside functions to help accomplish additional tasks.
I'm going to send you to the store with money to get groceries. But I need to know how you're doing at the store. So I'm also going to send your friend, and he'll call back home and let me know how things are going. I might even ask him to do other things for me, like drive you home with the groceries.
Sometimes, you need friends to do certain things, like setting a timeout (as exhibited by @nestedsoftware ). That's a 2-person job, someone to set the time and someone to actually do something.
Thank you so much .. !! :)