开发者

Calling a callback in javascript

开发者 https://www.devze.com 2023-01-18 04:50 出处:网络
I am not so strong in javascript. I have a common function that I call from many parts of my code passing them some parameters.

I am not so strong in javascript.

I have a common function that I call from many parts of my code passing them some parameters.

Can somebody help me on

  • how to define a new parameter for this function that should be a callback with no parameters passed from the caller (like many jquery plugins do)
  • how to handle the callback call inside the function

Giving advice regarding the solution, if there's a better one, et开发者_开发问答c.

thanks a lot!


It is actually quite simple.

function callback() {
    alert("I am in the callback!");
}

function work(func) {
    alert("I am calling the callback!");
    func(); 
}

work(callback);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号