Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
142
rated 0 times [  149] [ 7]  / answers: 1 / hits: 15393  / 14 Years ago, fri, october 1, 2010, 12:00:00

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!


More From » callback

 Answers
3

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);

[#95439] Wednesday, September 29, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austynp

Total Points: 505
Total Questions: 118
Total Answers: 106

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
austynp questions
;