Properly formatting JavaScript in JavaScript

2019-08-05 03:58发布

问题:

How can I automatically format JavaScript properly?

As an example, this:

(function(){(function(){alert('whatever')})()})()

Should become:

(function(){
    (function(){
        alert('whatever')
    })()
})()

回答1:

There is the jsbeautifier, you can find the source code at github.



回答2:

Try http://jsbeautifier.org/ - it's the same one used by jsfiddle.net on their "Tidy Up" button where you can try it out.