Last active
December 29, 2015 17:49
-
-
Save idx3d/7706466 to your computer and use it in GitHub Desktop.
callback description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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