Javascript解析器 [英] Javascript parser
问题描述
我想知道是否有一个工具可以用来在实际运行之前测试一些javascript代码?b
什么能检查
语法至少?我发现在编码
javascript时我犯的大多数错误都与语法有关。
这是一个典型场景:我使用像getElementByID这样的函数。注意
大D ...在Internet Explorer中我得到经典的对象不支持这个
的属性或方法。消息,行X,字符X,没有用,因为他们
指向我无法联系的地方。使用解析器或编译器可以很容易地发现这样的错误
。
Hi, I would like to know if there exists a tool that one can use to test
some javascript code before actually running it ? Something that would check
the syntax at least ? I found that most mistakes that I make when coding in
javascript are syntax-related.
Here''s a typical scenario: I use a function like getElementByID. Notice the
big D...In Internet Explorer I get the classic "object doesn''t support this
property or method" message, line X, char X that are of no use because they
point somewhere I can''t relate. Such an error could have been easily spotted
with a parser or compiler.
推荐答案
下载firefox。
http://getfirefox.com
在查看html页面的菜单中,转到工具/ Javascript
控制台。
如果你无法下载firefox,试试这个:
window.onerror = errHandler;
var msgArray = new Array(),urlArray = new Array(),lnoArray = new
Array() ;
//错误函数的参数(默认确定,不是我的
想法...):
//错误信息,发生错误的网址和行号
函数errHandler(msg,url,lno){
msgArray [msgArray.length] = msg;
urlArray [urlArray.length] = url;
lnoArray [lnoArray.length] = lno;
返回true;
}
函数displayErrors(){
var s =''Javascript错误报告\ nn \ n \\ n'\\ n';'
if(msgArray.length){
for(var i = 0; i< msgArray.length; i ++){
s + =''line''+ lnoArray [i] +'':\ n''+ msgArray [i] +''\ n\ n'';
}
alert(s);
}
}
然后只需调用''displayErrors()''来查看报告。
" return true"在错误处理程序中将保持Internet Exporer从
生成那些恼人的警报框(如果您安装了C ++调试器
,则调试器也不会加载)。
Download firefox.
http://getfirefox.com
In the menu when viewing your html page, go to Tools/Javascript
Console.
If you can''t download firefox, try this:
window.onerror=errHandler;
var msgArray = new Array(),urlArray = new Array(),lnoArray = new
Array();
//paramenters of error functions(determined by default, not my
idea...):
//error message, url where error occurred and line number
function errHandler(msg, url, lno) {
msgArray[msgArray.length] = msg;
urlArray[urlArray.length] = url;
lnoArray[lnoArray.length] = lno;
return true;
}
function displayErrors(){
var s=''Javascript Error Report\n\n\n'';
if(msgArray.length){
for(var i=0;i<msgArray.length;i++){
s+=''line ''+lnoArray[i]+'':\n''+msgArray[i]+''\n\n'';
}
alert(s);
}
}
then just call ''displayErrors()'' where you want to see the report. The
"return true" in the error handler will keep Internet Exporer from
generating those annoying alert boxes (and if you have the C++ debugger
installed, the debugger won''t load either).
" Jeff Robichaud"写了
"Jeff Robichaud" wrote
我想知道是否有一个工具可以用来在实际运行之前测试一些javascript代码?
的东西至少会检查语法?
Hi, I would like to know if there exists a tool that one can use to test
some javascript code before actually running it ? Something that would check the syntax at least ?
http://www.crockford.com/javascript/jslint.html
hth
-
Ivo
http://www.crockford.com/javascript/jslint.html
hth
--
Ivo
Firefox javascript控制台:我会想到这个技巧。
jslint:不错但是还不完整:它不会发现与错误拼写的
方法相关的错误。
谢谢大家!
Ivo < no@thank.you>在消息中写道
news:42 *********************** @ news.wanadoo.nl ...
Firefox javascript console: that will do the trick I think.
jslint: not bad but still incomplete: it won''t catch errors related to
methods that are misspelled.
Thank you guys!
"Ivo" <no@thank.you> wrote in message
news:42***********************@news.wanadoo.nl...
Jeff Robichaud写了
"Jeff Robichaud" wrote
我想知道是否有一个工具可以用来在实际运行之前测试一些javascript代码?什么会
Hi, I would like to know if there exists a tool that one can use to test
some javascript code before actually running it ? Something that would
检查
语法至少?
http://www.crockford.com/javascript/jslint.html
hth > -
Ivo
http://www.crockford.com/javascript/jslint.html
hth
--
Ivo
这篇关于Javascript解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!