либо так
createCounter=function(max){
var value=0
return function(){
with(console){
if(value>=max) return log("done")
log(++value)
}
}
}
counter=createCounter(3)
counter()
counter()
counter()
counter()
counter=createCounter(5)
counter()
counter()
counter()
counter()
counter()
counter()