Uniquely identify a function in JavaScript
<p>Is there any way I can uniquely identify a function without giving it an expando property? I've been just using "toString()" to identify the function, but when two functions are identical, they conflict.</p>

<p>The following sample code reproduces the problem. In my actual code, the key for the associative array "myfunctions" is built from other parameters as well. I don't want to generate a meaningless key since the developers using this code need to be able to rebuild this key at any time without holding a reference to some random key.</p>

<pre><code>var myfunctions = {};

(function(){
    var num = 1;
    function somefunc() {
     alert(num);
    }
    myfunctions[somefunc.toString()] = somefunc;
})();

(function(){
    var num = 2;
    function somefunc() {
     alert(num);
    }
    myfunctions[somefunc.toString()] = somefunc;
})();

for (var f in myfunctions) {
    myfunctions[f]();
}
</code></pre>

<p>When this code is run, only one alert fires, and it always has the message "2".</p>
