Callback Functions
Simple Callback Function Example
<button id="brew">Brew</button>
//init when window loaded
function init() {
document.getElementById('brew').onclick = function() {
brew(param, function() {
alert('Finished brewing ' + param + ' coffee');
});
};
var param = 'dark roast';
function brew(param, callback) {
alert('Started brewing ' + param + ' coffee');
callback();
};
}
window.onload = init;