Java Web Project Front-End specification (using namespaces to make JS deep solution coupled) _jsp programming

Source: Internet
Author: User
Tags java web

No rules. Radius, an excellent code architecture is not only easy to develop and maintain, but also an art of management and execution.

Over the past few years has experienced a lot of projects, the code between the strong coupling and writing is not standardized, poor maintenance of the problem. Here, through careful analysis, combined with their own coding habits summed up a set of applicable to the Javaweb project front-end writing specifications, and share with you.

PS: Thanks to a Hai creative, finishing the following (with file download):

I. Structure of the project

This is not very different from other items, I will draw out the template, easier to analyze and understand:


Explain: JS mainly includes extends (the introduction of the third party JS), module (the Project module of their own JS), Lib (reference package, here can also continue to split), module contains the specific modules in the JS. Common.js is the kernel namespace of JS.

Second, Common.js

To explain, globals as a global namespace, each module can be defined in this namespace domain (if there is not clear to learn the name of the namespace, this file is written dead on the line, do not have a specific understanding).

Third, Task.js

This file is the module in my project in the task module JS (example), module-level JS is generally a relatively independent of the page in the way out of the method, do not recommend all pages JS come in.

Explain: module-level JS mainly includes its own private properties and methods, and external exposure of JS properties and methods. Here we default to all internal private front all add "_", finally decide which methods and attributes exposed, is through the construction method constructor to external exposure.

Four, page index.jsp

Now look at how the JSP in the page JS and module JS is how to quote it, witness the decoupling and the time has come.



Explain: the page needs to introduce Common.js and Task.js, and then initialize it so that you can access the externally exposed methods and properties in the task module.

Page JS recommends that all variables be sent in a variable group, which is easy to maintain.

Controls on the page, such as the OnClick method recommended in JS Unified binding.

Summary: Through the above configuration, the biggest benefit is frequently introduced in the project JS file, eliminate the coupling between, and for different modules of the same name methods and properties will not affect each other, of course, the most important for sustainable development and maintenance, but also the enjoyment of art.

This article used my customary annotation style, of course, can vary from person to person, my principle is:

1. Module Introduction Code main concern: module description, responsible, related remarks, using double star annotation

/**

*

*/

2. For the module, the division of large areas, the habit of using double horizontal annotation:

//==================================================

Describe:

3. For the area, method annotation, through the past experience, not everyone is willing to write in detail, so I think simple and clear the best, using the general Comment:

Code description

Author's comments and other information (not limited)

4. For some important areas of the method, or want to distinguish between the delineation of the cell, using the star horizontal

/**************************** Description *****************************/

If there are good ideas you can discuss together, if you feel that the article write to their own little help, right when laugh.

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.