closure 的意思

終於有找到一個描述比較清楚,比較具體的 closure 解釋。

The function value (the object) that's created at runtime from this function literal is called a closure. The name arises from the act of "closing" the function literal by "capturing" the bindings of its free variables.


當 function literal 內部,用到了一些沒辦法從參數列中找到的變數,這些變數就成為了開放變數(free variable)。開放變數的存在,讓 function 成了 open term,還無法使用。所以它需要補捉 scope/context 內部中,有符合名字的變數,來填入這些開放變數、來 close function ,讓 function 成為 closed term

comments powered by Disqus