// Enclosing function (Внешняя (родительская) функция )
function numberGenerator() {
var num; // локальная "свободная" переменная
// Внутренняя (дочерняя) функция. Имеет доступ к переменной "num" благодаря замыканию
function checkNumber(num) {
num++; // Увеличиваем на единицу входящий параметр
console.log(num); // Выводим в консоль
}
return checkNumber; // Возвращаем дочернюю функцию
}
var number = numberGenerator(); // создаем экземпляр внешней функции
var numb = 5;
number(numb); // Вызываем и получаем "numb = numb + 1"
Last active
June 30, 2017 04:18
-
-
Save RinatValiullov/10539ff0aeee0e1fa9728e12894d2b86 to your computer and use it in GitHub Desktop.
Learn Closure (замыкание)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment