Код: Выделить всё
//A function that takes an argument, which is another function, that will be run after everything else above is done
function requestFunc(callBackFunc){
const request = new XMLHttpRequest();
request.open("GET", "https://somewebsite.com");
request.send();
callBackFunc(request.response);
}
//A function that logs the argument
function printFunc(response){
console.log(response);
}
//Calling requestFunc() and passing printFunc() as the argument
requestFunc(response => {
printFunc(response);
});
Подробнее здесь: https://stackoverflow.com/questions/797 ... javascript