-
closurejavascript 2020. 5. 28. 18:09
//closures function retirement(retirementAge){ var a = ' years left until retirement.' return function(yearOfBirth){ var age = 2020 - yearOfBirth; console.log((retirementAge - age) + a); } } var retirementUS = retirement(66); var retirementGermany = retirement(65); var retirementIceland = retirement(67); retirementUS(1990); retirementGermany(1990); retirementIceland(1990); //closures summary /* An inner function has always access to the variables and parameters of its outer function, even after the outer function has returned */
참조 : Udemy - The Complete JavaScript Course 2020 : Build Real Projects!
https://hyunseob.github.io/2016/08/30/javascript-closure/
'javascript' 카테고리의 다른 글
forEach에 대해서 참조한 블로그 + 여러가지 배열 메소드 (0) 2020.06.06 call, apply, bind (0) 2020.05.28 function (0) 2020.05.28 Creating Object (0) 2020.05.27 자바스크립트 this (0) 2020.05.22