What is a callback function?

前端 未结 21 2850
耶瑟儿~
耶瑟儿~ 2020-11-21 23:01

What is a callback function?

21条回答
  •  春和景丽
    2020-11-21 23:43

    What is callback?

    • In general, a telephone call made to return one that someone has received.
    • In computing, a callback is a piece of executable code that is passed as an argument to other code. When the function is done with its work (or when some event occurred), it calls your callback (it calls you back - hence the name) function.

    What is a callback function?

    • a callback function is like a Servant who "calls back" to his Master when he has completed a task.
    • a callback function is a function that is passed to another function (let's call this other function otherFunction) as a parameter, and the callback function is called (or executed) inside the otherFunction.
        function action(x, y, callback) {
            return callback(x, y);
        }
    
        function multiplication(x, y) {
            return x * y;
        }
    
        function addition(x, y) {
            return x + y;
        }
    
        alert(action(10, 10, multiplication)); // output: 100
    
        alert(action(10, 10, addition)); // output: 20
    

    In SOA, callback allows the Plugin Modules to access services from the container/environment.

    Analogy: Callbacks. Asynchronous. Non-blocking
    Real life example for callback

提交回复
热议问题