Is there anything bad about attaching a variable to a function in Javascript?
<p>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.</p>

<p>I'm currently doing it in this manner:</p>

<pre><code>
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
    }
}
</code></pre>

<p>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.</p>
