Javascript错误检查 [英] Javascript error checking

查看:70
本文介绍了Javascript错误检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,因为我之前的想法(通过

包装器调用函数)显然是如此糟糕,没有人可以建议任何

的改进,我会尝试一下不同的大头钉我的最终目标是让

轻松,轻松地检测和报告脚本错误。如果window.onerror无处不在,这可以轻松实现
,但它不是b $ b。我的新想法是将表面上类似于C'的assert()宏的东西组合在一起,或许类似于


函数断言(expr_as_string,cond){

var result = eval(expr_as_string);

if(cond == null){

cond = true;

}

if(result!= cond){

alert(''断言失败:''+ expr_as_string +''==''+结果+'',预期

''+ cond);

返回false;

}

返回true;

}


将用作


断言(''5!= 3''); // true

断言(''5 * 10 == 3''); // false


现在显然这可能是令人无法接受的混淆。

这就是为什么我要张贴并希望,拼命地,为建议

改进和/或其他想法。肯定给出了大量的脚本

那里有人设想了一个半合理的错误检查

框架......


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。

All right, since my previous idea (calling functions through a
wrapper) was apparently so awful no one could suggest any
improvements, I''ll try a different tack. My end goal is to make
detecting and reporting script errors easy and painless. This could
be accomplished easily if window.onerror were ubiquitous, but it is
not. My new idea is to hack together something superficially
resembling C''s assert() macro, perhaps something like

function assert( expr_as_string, cond ) {
var result=eval( expr_as_string );
if( cond == null ) {
cond=true;
}
if( result != cond ) {
alert( ''Assertion failed: ''+expr_as_string+''==''+result+'', expected
''+cond );
return false;
}
return true;
}

which would be used like

assert( ''5 != 3'' ); // true
assert( ''5*10 == 3'' ); // false

Now obviously this is, again, probably unacceptably obfuscatory.
That''s why I''m posting and hoping, desperately, for suggested
improvements and/or other ideas. Surely given the amount of script
that''s out there someone has conceived a half-reasonable error checking
framework...

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.

推荐答案

肯定给出了大量的剧本
设想了一个半合理的错误检查框架...
Surely given the amount of script
that''s out there someone has conceived a half-reasonable error checking
framework...




当然有。

Firefox有Venkman和javascript控制台,和MSIE有一个窗口

javascript调试器,我忘记了它的名字。


那个(使用这些工具测试好)和try / catch和良好的编码(即在使用之前检查对象)应该处理

几乎任何出现的东西,真的。


我的2当然。美分。



Sure they have.
Firefox has Venkman and the javascript console, and MSIE has a windows
javascript debugger whose name I forget.

That (good testing using these tools) and try/catch and good coding
with checks (i.e. checking for object before using it) should handle
pretty much anything that comes up, really.

My 2 cents, of course.


我同意nikki。


我写了一个应用程序运行到某些1MB(60,000行)的

Javascript,只有对象/属性检查(并且一次尝试捕获

用于保存文件),没有任何问题,所以我很难看到用途o f

错误检查框架。你能举一些你会用它的

应用程序吗?

I would agree with nikki.

I have written an application running to some 1MB (60,000 lines) of
Javascript, with only object/property checking (and a single try catch
for file saving) , with no problems, so I struggle to see the uses of
an error checking framework. Could you give some examples of
applications you would use it in?


Baconbutty< ju **** @ baconbutty .COM>写道:
Baconbutty <ju****@baconbutty.com> wrote:
我已经写了一个运行到大约1MB(60,000行)的Javascript的应用程序,只有对象/属性检查(和一次尝试捕获
对于文件保存),没有问题,所以我很难看到
错误检查框架的用途。你能给出一些你会用它的应用程序的例子吗?
I have written an application running to some 1MB (60,000 lines) of
Javascript, with only object/property checking (and a single try catch
for file saving) , with no problems, so I struggle to see the uses of
an error checking framework. Could you give some examples of
applications you would use it in?




那么60,000行的脚本从来没有出现意想不到的错误?我知道

我们的脚本是由人类编写和测试的,偶尔会出现bug.

in。如果Safari用户遇到其中一个bug,你怎么找到

关于它?我真的很难理解你是如何避免在60,000行剧本中犯错误的。


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。



So the 60,000 lines of script never, ever has unexpected bugs? I know
our script is written and tested by humans and occasionally bugs creep
in. If a Safari user encounters one of these bugs, how do you find
out about it? I''m really struggling to understand how you avoid ever
making a mistake in 60,000 lines of script.

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


这篇关于Javascript错误检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆