Is there any way to uniquely identify a function without providing it with the expando property? I just used "toString ()" to identify the function, but when the two functions are identical, they conflict.
The following code example reproduces the problem. In my actual code, the key for the "myfunctions" associative array is also built from other parameters. I donβt want to generate a meaningless key, since developers using this code should be able to rebuild this key at any time without reference to some random key.
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](); }
When this code is run, only one warning is triggered, and it always has a β2β message.
source share