I'm writing some Javascript code and I need to keep track of a global state. The state is only ever changed by a single function, but it needs to be widely accessible from other functions.
I'm currently doing it in this manner:
function foo(bar) {
var self = arguments.callee;
if (!self.state) {
self.state = 0; // called 0 times
} else {
self.state++; // increase the number of times i've been called
}
}
Is it sensible to bind the global state variable to the function like this? It's nifty but I'm worried that there's something dangerous that I've missed.