John Resig used function decompilation technique in his simple inheritance example. His technique with regular expression method was also used in jQuery library and the same technique was criticized on opera blog. On opera blog some guy wrote:
This is not a good idea because decompiling functions is an optional feature of the ES-262 spec. It is slow and requires too many resources for certain low-end platforms, so it is not supported by any of the Opera Mobile versions.
I’m well aware of Function.prototype.toString method and I also know about it’s varying implementation by different browser vendors. So to come to my question:
Is it possible to perform cross browser, reliable function decompilation at the current state?
If yes which one of techniques I mentioned above should I use? And why?
There is only one technique, and that’s the
toStringmethod of functions.If you are using a regex and its
testmethod, the argument will just implicitly be converted to a string – by calling itstoStringmethod.