What is a callback function?
相关问题
- Disable Browser onUnload on certain links?
- Jscrollpane - Fires a function when isAtBottom
- How to pass C# method as a callback to CLI/C++ fun
- Name for a method that has only side effects
- Callbacks with Python curses
相关文章
- How to create a CFuncType in Python
- Should client-server code be written in one “proje
- Algorithm for maximizing coverage of rectangular a
- Change loss function dynamically during training i
- Is there an existing solution for these particular
- What is Scope Creep? [closed]
- What is the best way to call into Swift from C?
- How can I modify .xfdl files? (Update #1)
I believe this "callback" jargon has been mistakenly used in a lot of places. My definition would be something like:
I think people just read the first sentence of the wiki definition:
I've been working with lots of APIs, see various of bad examples. Many people tend to name a function pointer (a reference to executable code) or anonymous functions(a piece of executable code) "callback", if they are just functions why do you need another name for this?
Actually only the second sentence in wiki definition reveals the differences between a callback function and a normal function:
so the difference is who you are going to pass the function and how your passed in function is going to be called. If you just define a function and pass it to another function and called it directly in that function body, don't call it a callback. The definition says your passed in function is gonna be called by "lower-level" function.
I hope people can stop using this word in ambiguous context, it can't help people to understand better only worse.
A callback function is one that should be called when a certain condition is met. Instead of being called immediately, the callback function is called at a certain point in the future.
Typically it is used when a task is being started that will finish asynchronously (ie will finish some time after the calling function has returned).
For example, a function to request a webpage might require its caller to provide a callback function that will be called when the webpage has finished downloading.