자바·파이썬·자바스크립트/자바스크립트

JavaScript Closures 101

바로이순간 2014. 6. 30. 11:12

http://www.youtube.com/watch?v=yiEeiMN2Khs


Published on Oct 12, 2013


A JavaScript closure is a function that has a pointer reference to a free variable. 

A free variable is one that has fallen out of scope after its parent function has returned. 

However, if that outer function still has some reference to the free var (normally through 

a function that gets returned, or through a method property), 

the variable will not get garbage collected because it will have a non-zero reference count. 

Thus, from outside the function, we can still access the inner variable by means of the closure.