【发布时间】:2011-05-11 15:21:24
【问题描述】:
javascript 在运行 JSLint 时对我大喊大叫,我不知道为什么。
/*jslint browser: true, devel: true, evil: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, newcap: true, immed: true */
var foo = function() {
try {
console.log('foo');
} catch(e) {
alert(e);
}
try {
console.log('bar');
} catch(e) {
alert(e);
}
};
foo();
它告诉我:
第 12 行字符 11 处的问题:'e' 已定义。
} catch(e) {
我有第二个catch(e) 似乎很不高兴。为什么这会是一个问题?它不是简单地将 e 设置为 catch 块内的局部变量吗?我是否需要为函数中的所有捕获错误唯一地命名局部变量?
【问题讨论】:
标签: javascript exception-handling error-handling try-catch jslint