What are free variables?

前端 未结 3 1739
日久生厌
日久生厌 2020-12-13 13:28

Javascript closure definition says :

A \"closure\" is an expression (typically a function) that can have free variables together with an environment

3条回答
  •  无人及你
    2020-12-13 14:21

    As an example:

    var myModule = (function (){
       var moduleVar; // closure variable
    
       return function(){
         // actual function
       }
    })();
    

    the variable defined there is a closure variable. it can be used all over the closure itself but is not part of a global namespace.

提交回复
热议问题