Javascript topic: How to build your own JS Library

Source: Internet
Author: User

First, let's take a look at this:

(Function (){

// RunCode

})();

The red brackets are an anonymous function, and the red brackets are separated, indicating that the function is a part. The green brackets indicate an operator, indicating that the function in the red brackets is to be run.

It is equivalent to defining an anonymous function and letting it run directly.

To build your own JS library, use the following template code:

(Function (){

Function $ (){

// Code

}

Window ['mynamespace'] ={} // define your own namespace // window ['ic'] = {}

Window ['mynamespace'] ['$'] = $; // register your $ function to the window namespace.

})();

Reference the functions in your own library on the page as follows:

<Body onload = "ic. $ ()"> </body> // IC is the defined namespace, and you can call the function in your own JS library file.

You can also write <body onload ="Window.IC. $ () "> </body> // window can be omitted.

Original article: http://hi.baidu.com/mutourenoo/blog/item/6cd36ac4fa1419a28326ac4c.html

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.