最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Calling a callback in javascript - Stack Overflow

programmeradmin1浏览0评论

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, etc.

thanks a lot!

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, etc.

thanks a lot!

Share Improve this question asked Oct 1, 2010 at 17:05 LorenzoLorenzo 29.4k50 gold badges128 silver badges224 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 20

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)

  1. 暂无评论