Skip to content

Instantly share code, notes, and snippets.

@idx3d
Last active December 29, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idx3d/7706466 to your computer and use it in GitHub Desktop.
Save idx3d/7706466 to your computer and use it in GitHub Desktop.
callback description
// callback - это третий аргумент функции asyncRandom.
// Это возможно, потому-что http://ru.wikipedia.org/wiki/Функции_первого_класса
function asycRandom(min, max, callback) {
var result = Math.ceil(Math.random() * (min - max) + max);
callback(result);
}
// Тут мы передаем третим аргументом анонимную функцию, которая принимает один аргумент num
// Этот аргумент num будет передан в колбек в фунции asycRandom, на строке 7. Там будет вызвана эта анонимная функция.
asycRandom(5, 15, function (num) {
console.log("callback called! " + num);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment