newbie approach: what is a javascript callback function?

前端 未结 7 2163
自闭症患者
自闭症患者 2020-11-28 12:49

Is just a function that executes after one other function that calls it, finishes?

Please I know (almost) nothing about programming, and I find it quite hard to find

7条回答
  •  借酒劲吻你
    2020-11-28 13:35

    A callback function is a function that is automatically called when another process ends. They are very usefull in asyncronous process, like get a page.


    EDIT

    Example: You want to get make a ajax call (get a page for example). And you want to run some function when donwload finishes.

    With jquery, you can use this:

    $.get('PageIWant.html', myCallBack);
    
    function myCallBack (data){
      alert('I have got the page!');
    }
    

提交回复
热议问题