Answer the question
In order to leave comments, you need to log in
How do callbacks work?
newbie. I smoke an example. I can't figure out how the callbacks work.
in the model (left). what I understand:
query(sql, there is a json response with data and an error). the rest is magic for me. please help me figure it out.
on the right in the controller when requesting the root, magic, then we say where we draw something from our object.
can someone explain the magic of callbacks? I will be very)
Answer the question
In order to leave comments, you need to log in
Mb on this example will be easier.
// асинхронная функция, которое аргументом передаем callback
function asyncFunction(callback) {
setTimeout(function() {
callback('Hello, World!'); // вызываем callback и передаем ему ответ 'Hello, World'
}, 2000);
}
// Вызываем асинхронную функцию, но чтоб получить ответ, нужно передать callback
// Т.е передаем другую функцию
asyncFunction(function(response) {
alert(response); // выводим ответ.
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question