开发者

Putting Curly braces into javascript if's without curly braces?

What I want: Transforming thi开发者_JAVA技巧s: if(a == b) //statement into: if(a == b) { //statement } Simply put: I want my single line if's to have their braces once again, and I need some program or plugin or some code, that would run over my code, and transform it to one with braces on every if.

How?

Thanks in advance, Danny.


In general, doing this yourself (as code) is a pretty tough task - basically, you would need to correctly parse JavaScript's grammar.

You may be able to write some regexes to do it in very specifically formatted cases (e.g. when your statement is 100% on the same line as the if or 100% on the line followwing the if; and the if itself is the first non-whitespace in the line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜