写一个闭包 ,每次调用都加1

 var getId=(function(){

        var  i=0;

      return function(){

      return i++

}

})()

console.log(getId);

console.log(getId);

原文地址:https://www.cnblogs.com/yangjinbo/p/10239802.html