JavaScript闭包(Closure)

1
2
3
4
5
6
7
8
9
function f1(){
    var n=999;
    function f2(){
      alert(n);
    }
    return f2;
  }
  var result=f1();
  result(); // 999

上面代码产生了闭包

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×