iOS Safari调试控制台 - 如何获取错误的行号?

时间:2022-05-18 23:51:58

I have a backboneJS project which loads the dependent files using a jQuery deferred object callback - the website loads fine on desktop, tested Android devices and on iPad with iOS 5.1 - a client brought to my attention that the site doesn't work on her iPad with iOS 4.3.5. Here is my code:

我有一个backboneJS项目,它使用jQuery延迟对象回调加载依赖文件 - 网站在桌面,经过测试的Android设备以及带有iOS 5.1的iPad上正常加载 - 客户端引起我的注意,该网站无法在iPad上运行使用iOS 4.3.5。这是我的代码:

$.when(
    // Load the stuff here...
).done(
    // Call jQuery DOM ready code here...
).fail(
    function () {
        for(var i=0; i<arguments.length; i++) {
            console.log(arguments[i]);
        }
    }
);

This is what is sent to the debug console in Safari (minus the line number of the console.log statement):

这是发送到Safari中的调试控制台的内容(减去console.log语句的行号):

[object Object]
parseerror
SyntaxError: Parse error

Well that just doesn't help me at all - any ideas how I can pinpoint that parse error without blindly debugging through 15 backbone views and models? Any known old iOS safari bugs with Backbone or jQuery deferreds that I missed during my troubleshooting research?

好吧,根本没有帮助我 - 任何想法如何能够找出解析错误而不盲目调试15个主干视图和模型?在我的故障排除研究期间,我错过了任何已知的旧的iOS safari错误与Backbone或jQuery延迟?

Edit: Using the following versions -

编辑:使用以下版本 -

Backbone.js (unminified) 0.9.1
jQuery (unminified) 1.8.0

2 个解决方案

#1


1  

Fixed the issue. Found a line of code where the property name was class, like myObj.class = 'foo'; and apparently class is a reserved word in older JS parsers. Changed it to className and it worked.

修复了这个问题。找到属性名称为class的代码行,如myObj.class ='foo';显然,类是旧的JS解析器中的保留字。将其更改为className,它工作正常。

On that note, I would still like to know how to view the line number of the parse error in the iOS Safari debug console. If anybody can provide that answer I'll accept it.

在这方面,我仍然想知道如何在iOS Safari调试控制台中查看解析错误的行号。如果有人能提供答案,我会接受。

#2


0  

Nikoshr has the right idea, though more specifically you should stringify the object being passed in the arguments. The debug console will truncate about everything so just replace the page content with the dump for your debugging efforts. It won't show any line number likely but if there is a parse error you'll likely see the object screwed up somehow; truncated response text from an ajax call or something - I only mention that because you are // Load the stuff here so I imagine you're using $.getScript or something else that will return a deferred object. If so, try this:

Nikoshr有正确的想法,但更具体地说,你应该对参数中传递的对象进行字符串化。调试控制台将截断所有内容,因此只需将页面内容替换为转储以进行调试。它不会显示任何行号,但如果存在解析错误,您可能会看到该对象以某种方式搞砸了;来自ajax调用的截断响应文本或其他东西 - 我只是提到,因为你是//在这里加载东西所以我想你正在使用$ .getScript或其他会返回延迟对象的东西。如果是这样,试试这个:

$.when(
    // Load the stuff here...
).done(
    // Call jQuery DOM ready code here...
).fail(
    function () {
        document.write(JSON.stringify(arguments[0]));
    }
);

#1


1  

Fixed the issue. Found a line of code where the property name was class, like myObj.class = 'foo'; and apparently class is a reserved word in older JS parsers. Changed it to className and it worked.

修复了这个问题。找到属性名称为class的代码行,如myObj.class ='foo';显然,类是旧的JS解析器中的保留字。将其更改为className,它工作正常。

On that note, I would still like to know how to view the line number of the parse error in the iOS Safari debug console. If anybody can provide that answer I'll accept it.

在这方面,我仍然想知道如何在iOS Safari调试控制台中查看解析错误的行号。如果有人能提供答案,我会接受。

#2


0  

Nikoshr has the right idea, though more specifically you should stringify the object being passed in the arguments. The debug console will truncate about everything so just replace the page content with the dump for your debugging efforts. It won't show any line number likely but if there is a parse error you'll likely see the object screwed up somehow; truncated response text from an ajax call or something - I only mention that because you are // Load the stuff here so I imagine you're using $.getScript or something else that will return a deferred object. If so, try this:

Nikoshr有正确的想法,但更具体地说,你应该对参数中传递的对象进行字符串化。调试控制台将截断所有内容,因此只需将页面内容替换为转储以进行调试。它不会显示任何行号,但如果存在解析错误,您可能会看到该对象以某种方式搞砸了;来自ajax调用的截断响应文本或其他东西 - 我只是提到,因为你是//在这里加载东西所以我想你正在使用$ .getScript或其他会返回延迟对象的东西。如果是这样,试试这个:

$.when(
    // Load the stuff here...
).done(
    // Call jQuery DOM ready code here...
).fail(
    function () {
        document.write(JSON.stringify(arguments[0]));
    }
);