1. 程式人生 > >JavaScript 教程 之基礎教程

JavaScript 教程 之基礎教程

ext 分析 java .html doc tac body cli doctype

1.js 錯誤

var objClass = {
    foo:1,
    bar:2
};

function printf() {
    var aaa:objClass;
    aaa.foo = 2;
    console.log(objClass.bar);
}
function throwIt() {
    throw new Error("");
}

function catchIt() {
    console.log(catchIt.name);
    try {
        throwIt();
    }catch
(e) { console.log(e.stack); } }
技術分享圖片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DataType</title>
    <script type="text/javascript" src="scripts/dataType.js"></script>
</head>
<body>
<p onclick="catchIt();return false;">Test</p>
</body>
</html>
View Code

明明定義了方法,卻報錯誤,多次嘗試後,分析為js裏面有錯誤,導致編譯其實是不過的,所以加載js是有問題的。

catchIt
Error
    at throwIt (http://localhost:63343/H51/scripts/dataType.js:7:11)
    at catchIt (http://localhost:63343/H51/scripts/dataType.js:13:9)
    at HTMLParagraphElement.onclick (http://localhost:63343/H51/DataType.html:9:38)

這個就是callstack。

JavaScript 教程 之基礎教程