首页 > 代码库 > js closure

js closure

var f = ( function() {
        var a = 1;
        return () => {
            a++;
            console.log(a);
        }
}());

// 2 3 4
f()
f()
f()

  

js closure