article

callback - overview

[WHAT]

  1. [] a 'callback' refers to a function that we are passing into another function as an arguement. 

[WHY]

  1. [] the callback function that we pass into the calling function(aka the callee), will be executed once the callee function has completed execution. 

[WHERE]

  1. [] callback - a primer on using callbacks,

[WHEN]

  1. [] to use a callback - when you want to execute another function immediately after the current function has completed its own execution

[EXAMPLE]

  1. first function
getDirectionsToLocation(callback){
   var directions = "head 4 miles east, turn right at stop sign.Then head 2mile west. location is on left hand side of road"
   callback;
}
  1. second function
travelToLocation(){
        
}
getDirectionsToLocation(travelToLocation);

[HOW-TO]

  1. ] pass a callback by reference
    1. ] in the above example we passed the callback arguement(doSomethingMore) by reference,
  2. ] pass a callback by value
    1. ] we can also pass callback arguements by value, aka we are passing the function body as the arguement
    2. ] doSomething(function(){console.log name;})

[REFERENCE]

  1. ]
( aka higher order function)
  1. // PASTE the first function into your javascript console and execute it, nothing will happen
  2. ] function doSomething(){
  3.     var message = "hello";
  4. }
  5. // PASTE the following function,
  6. ] function doSomethingMore(){
  7.    console.log name;
  8. // PASTE the following function call into the console window and run it, CONGRATS you just created your first callback
  9. ] doSomething(doSomethingMore);
Details Photos Edit more

Details

ID: 4607

NAME: 008-callback

DESCRIPTION: by Don Sagrott - Understanding 'callbacks' - this fundamental programming practice is a very simple and very effective method to

AUTHOR: article.author/s

EDITOR: article.editor/s

PUBLISHER: article.publisher/s

STATUS: Write

PRIORITY: -5

OWNER ID: 75

Content Photos Edit more

photos

page_photo

actions

Email Email-Owner SMS and