【问题标题】:sammy.js get handler hiding errorssammy.js 获取处理程序隐藏错误
【发布时间】:2013-03-20 10:30:48
【问题描述】:

在使用 0.7.4(也有 0.7.1)版本的 sammy.js 库时,发现如果在执行get 处理函数,控制台不会打印任何内容。

例如,在下面的代码中,sn-p 尽管没有名称为 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>

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

提前非常感谢

【问题讨论】:

    标签: javascript error-handling sammy.js


    【解决方案1】:

    结果比我想象的要容易 - 在检查 sammy.js 的来源后,发现 raise_errors 标志默认设置为 false 以管理错误报告。 p>

    所以,将上面的代码修改为:

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

    开始显示不错的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 2015-06-02
      相关资源
      最近更新 更多