写一个闭包 ,每次调用都加1 var getId=(function(){ var i=0; return function(){ return i++ } })() console.log(getId); console.log(getId);