0

在使用0.7.4版本 (也是0.7.1)的 sammy.js 库时,发现如果在处理函数执行期间发生某些错误,则不会将任何内容打印到控制台。get

例如,在以下代码片段中,尽管不notExistingFunction存在具有名称的函数,但不会将任何内容打印到控制台:

<html>
    <head>
        ...
        <script src="/path/to/jquery-1.5.2.min.js"></script>
        <script src="/path/to/sammy-0.7.4.min.js"></script>
        ...
    </head>
    <body>
        <script>
            $(document).ready(function() {
                var sammy = Sammy(function() {
                    this.get('#someAnchor', function() {
                        // this function doesn't exist
                        notExistingFunction();
                    });
                });
                sammy.run();

                // this should lead to execution of above handler
                window.location.hash = '#someAnchor'; 
            });
        </script>
        ...
    </body>
</html>

这确实使页面的故障排除变得复杂,有人也遇到过这种情况吗?这是预期的行为还是错误?有什么解决方法吗?

非常感谢提前

4

1 回答 1

1

结果比我想象的要容易——在检查了sammy.js的来源后,发现默认情况下raise_errors设置了 somewhy 标志来false管理错误报告。

因此,将上面的代码修改为:

<html>
    <head>...</head>
    <body>
        <script>
            ...
            sammy.raise_errors = true;
            sammy.run();
            ...
        </script>
    </body>
</html>

开始显示不错的错误。

于 2013-03-20T10:54:06.963 回答