javascript - Callback() Node Js -


i'm confused program. bought book called "node js, mongodb, , angularjs web development" brad dayley. found program demonstrate called closure, , shows program example. first part of program.

function logcar(logmsg, callback){     process.nexttick(function(){         callback(logmsg);     }); }  var cars = ["ferrari", "porsche", "bugatti"];  for(var idx in cars){     var message = "saw " + cars[idx];     logcar(message, function(){         console.log("normal callback: " + message);     }) } 

i've been trying figure out how program functions entire hour, can't figure out function of callback(logmsg).

i know basic question, can't wrap head around it.

callback function pass logcar(). when logcar completes doing whatever supposed do, call callback function. inside loop, call logcar() this..

logcar(message, function(){     console.log("normal callback: " + message); }) 

here, function() {..} callback function , called once logcar done executing. in case, callback function you've provided console.log message you've passed first parameter. have passed function perform different callback too.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -