In his detailed explanation of asynchronous code in this question: Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference Fabrício Matté gives the following example:
// 1. Call helloCatAsync passing a callback function,
// which will be called receiving the result from the async operation
helloCatAsync(function(result) {
// 5. Received the result from the async function,
// now do whatever you want with it:
alert(result);
});
// 2. The "callback" parameter is a reference to the function which
// was passed as argument from the helloCatAsync call
function helloCatAsync(callback) {
// 3. Start async operation:
setTimeout(function() {
// 4. Finished async operation,
// call the callback passing the result as argument
callback('Nya');
}, 2000);
}
I am trying to remove the anonymous function (I find it easier to read & understand the code that way). How should I do that?