Javascript 不匹配的括号:快速找到它们的方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7597752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mismatched parentheses: a quick way to find them?
提问by Chris Tolworthy
I just rearranged a very large JavaScript file. I now get "Unexpected end of input." Somewhere in those hundred of functions, one has lost (or gained) a bracket. What's the quickest way to find it?
我刚刚重新排列了一个非常大的 JavaScript 文件。我现在得到“意外的输入结束”。在这数百个函数中的某个地方,一个人失去了(或获得了)一个括号。找到它的最快方法是什么?
回答by mamoo
You could try to parse your file with lint: http://www.javascriptlint.com/online_lint.php
您可以尝试使用 lint 解析您的文件:http: //www.javascriptlint.com/online_lint.php
If you have problems with the size of the file try to split it into smaller ones...
如果文件大小有问题,请尝试将其拆分为较小的文件...
回答by CESDewar
A good trick when missing a brace in eclipse is to go to the final brace in the source module and double-click it. That will highlight all the way back to what it THINKS is the matching open brace. Where it highlights back to is invariably the START of where the problem is, so skip that open brace and go to the next one and start double-clicking open braces and you will usually find where the brace is missing pretty quickly. I learnt that the hard way with a source code file of 20,000+ lines of code and getting hundreds of errors without the slightest indication as where the real problem was as the errors started appearing thousands of lines earlier in the code.
在 eclipse 中缺少大括号时的一个好技巧是转到源模块中的最后一个大括号并双击它。这将一直突出显示它认为匹配的开放式大括号。它突出显示的地方总是问题所在的开始,所以跳过那个开括号并转到下一个并开始双击开括号,你通常会很快找到括号丢失的地方。我了解到,使用包含 20,000 多行代码的源代码文件并在没有丝毫迹象表明真正问题所在的情况下出现数百个错误的艰难方法,因为错误开始出现在代码中的数千行之前。
回答by Dave Newton
Re-format the file using something that indents well. Look for something that's too far to the left.
使用缩进良好的内容重新格式化文件。寻找离左边太远的东西。
回答by Steve Wellens
Minimize the nesting of functions. It reduces the quality of the code (maintainability-wise).
尽量减少函数的嵌套。它降低了代码的质量(可维护性方面)。