Code Explanation of JavaScript learning

Source: Internet
Author: User

The

Adds a comment to your code, which I hope will help you.
<script type= "Text/javascript" charset= "utf-8"
(function () {
var doc = document,//define individual names for the document object. Local variable access faster than global
WA = doc.createelement (' script '),//Create a <script> tag
s = doc.getelementsbytagname (' script ') [0];//Find the first <script> tag, it is possible that it is its own
Wa.type = ' text/javascript ';//Add attributes to the <script> tag you just created, the label at this point: <script Type= "Text/javascript"
Wa.charset = ' utf-8 ';//Set CharSet property to label,<script> don't you need this?
Wa.async = true;//do not know what this is, have not seen
Wa.src = (' https: ' = = Doc.location.protocol? ' https://': ' http://') + ' js.t.sinajs.cn/open/analytics/js/suda.js?version=20111118190824.js ';
//Add src attribute to <script> tag, URL, if the current document's protocol is HTTPS https://otherwise http://then link to the path of JS Js.t.sinajs.cn/open/analytics/js /suda.js?version=20111118190824.js
//Finally this label becomes a
//<script type= "Text/javascript" charset= "Utf-8" async= " True "Src=" http (s)://js.t.sinajs.cn/open/analytics/js/suda.js?version=20111118190824.js "></SCR ipt>// I've manually added a space here.Grid, or it will conflict with the last script end tag, note
S.parentnode.insertbefore (WA, s);}) ()//finally add this tag to the first <script> label on the page, and
/*
The entire function is included in an anonymous function to avoid conflicts with the name of the variable in the outside world.
The whole process is a dynamic loading of external JS file process, the advantage is that the browser will download the JS file in parallel, speed up the loading speed of the page.
In fact, it is better to uninstall those doc references at the end,
doc = null;
WA = null;
s = null;
*/
</script>

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.