Javascript function as a parameter to another function?

后端 未结 7 1088
执念已碎
执念已碎 2021-01-31 06:17

I\'m learning lots of javascript these days, and one of the things I\'m not quite understanding is passing functions as parameters to other functions. I get the concept

7条回答
  •  被撕碎了的回忆
    2021-01-31 06:53

    Callbacks. Say you're doing something asynchronous, like an AJAX call.

    doSomeAjaxCall(callbackFunc);
    

    And in doSomeAjaxCall(), you store the callback to a variable, like var ajaxCallback Then when the server returns its result, you can call the callback function to process the result:

    ajaxCallback();
    

提交回复
热议问题