JS Object-Oriented Learning Note II (Debug debugging method)

Source: Internet
Author: User


1. JS Debugging


Obviously, JS debugging can only be printed with alert

alert (ID);


for complex data types, we can then eject them by converting them to JSON format
Alert (json.stringify (data));



2. DOM Information Debugging
For the information we need to get, we can print it to the DOM element as required.


document.write (data); Will overwrite the entire document



3. Debugging at the terminal
Exit after printing the required information directly on the terminal

Var_dump () Print_r ()




4. JS other error information processing
/*================== most browsers support a small subset of =====================*/window.onerror=handleerrfunction HANDLEERR (msg,url,l) that are not supported {    txt= "there was a error on this page.\n\n"    txt+= "error:" + msg + "\ n"    txt+= "url:" + URL + "\ n"    txt+= "L INE: "+ L +" \ n "    txt+=" click OK to continue.\n\n "    alert (TXT)    return true;}

5. Try Catch debugging

/*================== browsers support ====================*/    try{      adddlert ("Welcome guest!");    }    catch (Err) {          txt= "This page has an error. \ n ";          txt+= "Error Description:" + err.message + "\ n";          txt+= "Click OK to continue. \ n ";          alert (TXT);   }



6. Of course we can use Console.log if we check for errors on the PC-side browser
Console.log (data);







JS Object-Oriented Learning Note II (Debug debugging method)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.