Set a unified entrance _javascript technique for the JS code of the Application section

Source: Internet
Author: User
Tags function definition
JavaScript is a scripting language, where the browser will be executed, which is convenient for programming, but also easy to make the program too messy and fragmented.

JS from the function can be divided into two parts-the framework part and the application part, the framework part provides the JS code the organization function, including defines the global variable, the namespace method and so on, each page will have the same or the similar frame. The Application section provides the function logic of the page, the different pages will have different functions, and the Code of the different page application parts is not the same.

To the application section of the JS code a unified entry, namely:
Copy Code code as follows:

<script type= "Text/javascript" >
function init () {
//==================================================
Comments
function, engineer name, contact method of engineer, time
//=================================================
(function () {
... aaaaaaaaaaa
})();
(function () {
... bbbbbbbb
})();
}
</script>

The init () function can be called at the bottom of the page
Copy Code code as follows:

The =======init () call belongs to the frame part code ==========

<script type= "Text/javascript" >
Init ();
</script>

The =======init () call belongs to the frame part code =========

Note: The framework part of the code is mainly divided into:

1. Namespace function definition

2, function init () {} write the application part of JS

3, the Init () function call "in case the body does not write init (), but called, can be written in the following way"
Copy Code code as follows:

<script type= "..." >
if (init) {
Init ();
}
</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.