最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

debugging - Can't find JavaScript Syntax Error - Stack Overflow

programmeradmin0浏览0评论

I'm just about to freak out. I currently have to work on a website that some other guy did and I am asked to maintain etc. It uses jQuery and a bunch of drupal modules. At some point i get some syntax error, so that some js works, and some does not. My big big problem is to find the syntax error. Neither Firebug, nor WebInspector give me decent information:

Error: uncaught exception: Syntax error, unrecognized expression: //

Yeah… that's it. No lines, no filename, no more hints. Has anyone an idea how to deal with this?

Thanks for any usefull hints.

I'm just about to freak out. I currently have to work on a website that some other guy did and I am asked to maintain etc. It uses jQuery and a bunch of drupal modules. At some point i get some syntax error, so that some js works, and some does not. My big big problem is to find the syntax error. Neither Firebug, nor WebInspector give me decent information:

Error: uncaught exception: Syntax error, unrecognized expression: //

Yeah… that's it. No lines, no filename, no more hints. Has anyone an idea how to deal with this?

Thanks for any usefull hints.

Share Improve this question asked Sep 10, 2010 at 14:14 nocksocknocksock 5,5276 gold badges41 silver badges66 bronze badges 1
  • I'm surprised that this is possible. Even if it was generated code that's being evaluated, eval() errors still are more informative than your example. – slikts Commented Sep 10, 2010 at 14:30
Add a ment  | 

4 Answers 4

Reset to default 4

you might try a tool like the closure piler, which will give warnings and errors for blocks of code. otherwise, it's brute force with alert('checkpoint'); to determine how far into your code you get before things break.

I believe Chrome's console pinpoints the line of the error.... Right-click on the page > Inspect element, then in the bottom right corner of the window that pops up, click on the red X icon, then click on the link for the error, enable Resource tracking if necessary...

Also, put the code trough JSLint and correct the code accordingly ...

I'd start by menting out all but one javascript include at a time in the html, if possible (unless they're a tangled mess of dependencies). Other than that, can you try using a debugger to step through it line by line? Finally, if it's not too much work, maybe it's worth writing unit tests. It'll also help you fully understand the person's code, and probably identify any deeper logic-level bugs.

JSLint may be what you need, but I bet it finds a lot more problems than just your elusive syntax error.

发布评论

评论列表(0)

  1. 暂无评论