js closure

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

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

  

原文地址:https://www.cnblogs.com/ax-null/p/6778362.html