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.
![javascript tosource javascript tosource](http://lh3.ggpht.com/-GUfgokb2s4Y/ThaUmHXkExI/AAAAAAAACFU/R23H-QY8DI4/image%25255B2%25255D.png?imgmax=800)
OUTPUT
![javascript tosource javascript tosource](http://lh4.ggpht.com/-c9uTBf-Rvks/ThaUm3kyW4I/AAAAAAAACFY/Z-fVZP2M_NY/image%25255B5%25255D.png?imgmax=800)
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