Friday 28 June 2019

Callback Functions - How do they actually work?

I'm a little curious about something, being new to full-stack development. I've written a lot of MATLAB tools, FORTRAN processes, and C/C++ and assembly doing embedded system develoment, but this concept is very new to me.​When I use express and pass a callback function to a route like:appRouter.get("/", function (req,res){ doSomething(); } how are the parameters "req" and "res" actually passed to the callback? I'm declaring the callback function, and somehow also passing those objects through to that function's execution context?Also, when retrieving data from my controller/model, I have to pass a callback function to the asynchronous query method, which somehow has a response object already embedded in it?​How is all of this working, beneath the scenes? Is there an analogy or description that might help me understand how all this works?​Thanks in advance.

Submitted June 28, 2019 at 10:58PM by f6engineer

No comments:

Post a Comment