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)
Callback Function A function which passed to another function as an argument.
Note: In above example test_function used as an argument for setTimeout function.
A callback function, also known as a higher-order function, is a function that is passed to another function as a parameter, and the callback function is called (or executed) inside the parent function.
Here we have pass a function as a parameter to the click method. And the click method will call (or execute) the callback function we passed to it.
Call After would be a better name than the stupid name, callback. When or if condition gets met within a function, call another function, the Call After function, the one received as argument.
Rather than hard-code an inner function within a function, one writes a function to accept an already-written Call After function as argument. The Call After might get called based on state changes detected by code in the function receiving the argument.
One important usage area is that you register one of your function as a handle (i.e. a callback) and then send a message / call some function to do some work or processing. Now after the processing is done, the called function would call our registered function (i.e. now call back is done), thus indicating us processing is done.
This wikipedia link explains quite well graphically.
A callback function is a function you specify to an existing function/method, to be invoked when an action is completed, requires additional processing, etc.
In Javascript, or more specifically jQuery, for example, you can specify a callback argument to be called when an animation has finished.
In PHP, the
preg_replace_callback()
function allows you to provide a function that will be called when the regular expression is matched, passing the string(s) matched as arguments.A callback function is a function you pass (as a reference or a pointer) to a certain function or object. This function or object will call this function back any time later, possibly multiple times, for any kind of purpose :
...
So describing a callback as a function being called at the end of another function or task is overly simplifying (even if it's a common use case).