Javascript function as a parameter to another function?

后端 未结 7 1085
执念已碎
执念已碎 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();
    
    0 讨论(0)
提交回复
热议问题