I first thought of looking out for a similar approach implemented in one of the javascript minifiers. But on further digging, I found that JavaScript has a toSource() method. The drawback is it is gecko-only and works only in Firefox. Since the source code had to viewed by only the developers who were debugging the code, ‘works-only-on-firefox’ was accepted.
Here’s the solution in case you have a similar requirement and are ok with a non-standard solution.
OUTPUT
As you can see, toSource returned only the JavaScript source and not comments. I really wish this was cross-browser. I will probably try my hands on the JSON.stringify method and see if something similar can be achieved.
Tweet
1 comment:
wow, good & cool discovery, thank for sharing, let me try it; but it'll display source code on in-line mode?
Post a Comment