JavaScript learning-code explanation

Source: Internet
Author: User

 

Add comments to this Code, hoping to help you.

<Script type = "text/javascript" charset = "UTF-8">

(Function (){

Var doc = document, // define an alias for the document object. Local variable access speed is faster than global

Wa = doc. createElement ('script'), // create a <script> tag

S = doc. getElementsByTagName ('script') [0]; // find the first <script> tag, which may be its own

 

Wa. type = 'text/javascript '; // Add attributes to the newly created <script> tag. The Tag: <script type = "text/javascript">

Wa. charset = 'utf-8'; // set the charset attribute for the tag. <script> do not need this attribute?

Wa. async = true; // I don't know what this is. I have never seen it before.

Wa. src = ('https: '= doc. location. protocol? 'Https: // ': 'http: //') + 'js .t.sinajs.cn/open/analytics/js/suda.js? Version = 20111118190824. js ';

// Add the src attribute to the <script> label, URL. If the protocol of the current document is https, https: // otherwise http: // then link the js path js.t.sinajs.cn/open/analytics/js/suda.js? Version = 201111182.16.js

// The tag becomes

// <Script type = "text/javascript" charset = "UTF-8" async = "true" src = "http (s): // js.t.sinajs.cn/open/analytics/js/suda.js? Version = 201111184252.16.js"> </scr EPT> // here I manually add a space, otherwise it will conflict with the end tag of the last script. Please note that

 

S. parentNode. insertBefore (wa, s) ;}) (); // Add this tag to the back of the first <script> tag on the page,

/*

The entire function is included in an anonymous function to avoid conflicts with external variable names.

The whole process is a process of dynamically loading external js files. The advantage of this is that the browser will download js files in parallel to speed up page loading.

In fact, it is better to unmount the references of those doc files at the end,

Doc = null;

Wa = null;

S = null;

*/

</Script>

 

From Hurry's column

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.