Two examples, one in PHP:
function adder($i){
static $a = 0;
$a += $i;
return $a;
}
A similar effect can be achieved with closures in javascript:
var adder = (function(){
var a = 0;
return function(i){
a += i;
return a;
}
})();
In javascript I've really just created an object. Implementation details not withstanding, does stateful-functions have a formal name?