Self-overwriting functions
Next pattern – a function that overwrites itself, a self-redefining function. Pretty similar to functions that return functions, but this time the function is re-implemented from the inside, not returned.
function next() { var count = 1; next = function() { return ++count; }; return count; } next(); // 1 next(); // 2
Tags: Functions, overwriting, self-definition