Skip to content

Instantly share code, notes, and snippets.

@accessomnath
Created February 10, 2020 17:06
Show Gist options
  • Save accessomnath/5b19af190643be1903753abe12225782 to your computer and use it in GitHub Desktop.
Save accessomnath/5b19af190643be1903753abe12225782 to your computer and use it in GitHub Desktop.
function tryMe (param1, param2) {
alert(param1 + " and " + param2);
}
function callbackTester (callback) {
callback (arguments[1], arguments[2]);
}
callbackTester (tryMe, "hello", "goodbye");
// --------------------------------
// callback function
function tryMe (param1, param2, param3) {
alert (param1 + " and " + param2 + " " + param3);
}
// callback executer
function callbackTester (callback) {
//this is the more obivous scenario as we use callback function
//only when we have some missing value
//get this data from ajax or compute
var extraParam = "this data was missing" ;
//call the callback when we have the data
callback(extraParam);
}
// test function
callbackTester (function(k) {
tryMe("hello", "goodbye", k);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment