gpt4 book ai didi

javascript - sammy.js获取处理程序隐藏错误

转载 作者:行者123 更新时间:2023-12-03 08:34:04 25 4
gpt4 key购买 nike

在使用 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>

这确实使页面的疑难解答复杂化了,有人也经历过吗?这是预期的行为还是错误?有什么解决方法吗?

在此先多谢

最佳答案

事实证明,这比我想的要容易-在检查 sammy.js 的源之后,发现默认情况下某种raise_errors标志设置为false,它可以管理错误报告。

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

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

开始显示不错的错误。

关于javascript - sammy.js获取处理程序隐藏错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15521032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com