Callback Function Example Clarification


Callback Function Example Clarification

Below is a snippet of code, I am fairly certain that it is not a callback function for reasons I explained below, but I could use some clarification.

Example :

var start = function () { var loops = 3 , total = 0; for (var i = 0; i < loops; i++) { total += next(i); } done(total); } var next = function (num) { var myNum = num * num; return myNum; } var done = function (num) { console.info('Added up to', num); } 

This would not be an example of a callback correct? In order for it to be considered a callback function, there must be a higher order function that accepts another function as a parameter, and in our example the start function does not accept other functions as parameters. If this is not a callback, then what is the term for what is going on here? Because the start function has access to other function calls inside of it for example the next function on the line total += next(i).

Thanks

Submitted August 10, 2017 at 10:35PM by bluehabit
via reddit http://ift.tt/2fvTUsG

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s