任何人都可以解釋我爲什麼:是什麼導致這些JavaScript驗證錯誤(隱含的全局和已定義的變種)?
function doAjax() {
var xmlHttpReq = false;
try { // Firefox, Opera 8.0+ and Safari
xmlHttpReq = new XMLHttpRequest();
}
catch (e) { // Internet Explorer
try {
xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX. Please use an AJAX compatible browser.");
return false;
}
}
}
xmlHttpReq.open('GET', 'handler.php', true);
xmlHttpReq.onreadystatechange = function() {
if (xmlHttpReq.readyState == 4) {
var response = xmlHttpReq.responseText;
handleAjaxResponse(response);
}
};
xmlHttpReq.send(null);
return true;
}
導致以下驗證錯誤:由JSlint.com
Error:
Implied global: ActiveXObject 8, XMLHttpRequest 4, alert 15, handleAjaxResponse 24
Problem at line 10 character 16: 'e' is already defined.
catch (e) {
Problem at line 14 character 20: 'e' is already defined.
catch (e) {
的JavaScript驗證
謝謝,所以重命名爲例如。 e1,e2和e3會更清潔嗎?它對我來說看起來並不是很乾淨 - 上面的例子是從我相信的W3C複製的。 – Tom 2009-01-04 16:22:37
不,重命名'e's不會是「更清潔」。 JSLint顯示錯誤和警告。這些只是警告,通過使用'e',您可以使該塊中的前一個錯誤對象不可用。如果你需要第二個捕獲中的第一個'e',你會想要重命名。我會忽略這個警告。 – Prestaul 2009-01-04 16:29:34