newbie approach: what is a javascript callback function?

前端 未结 7 2172
自闭症患者
自闭症患者 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:32

    Trying to get a more general and simple example, I figured out the following, and with arguments to performe a calculation with two numbers: x and y.

    function doMath (x,y,myMath) {return myMath(x,y);}
    
    function mult (a,b){return a*b;}
    function sum (a,b){return a+b;}
    
    alert(doMath(2,2,sum))    
    

    where myMath is the callback function. I can replace it for any function I want.

提交回复
热议问题