JavaScript modular Programming (i) the format of modules

Source: Internet
Author: User

As Web sites become "Internet apps," JavaScript code embedded in Web pages is growing larger and more complex.

Web pages are more and more like desktop programs, need a team division of work, progress management, unit testing and so on ... Developers have to use the software engineering approach to manage the business logic of Web pages.

JavaScript modular programming has become an urgent requirement. Ideally, developers only need to implement the core business logic, and others can load the modules that others have already written.

However, JavaScript is not a modular programming language, and it does not support "classes" (class), not to mention "modules" (module). (The sixth edition of the ECMAScript Standard, which is being developed, will formally support "classes" and "modules", but it still takes a long time to put into practice.) )

The JavaScript community has made a lot of effort to implement the "module" effect in the existing operating environment. This paper summarizes the best practices of current "JavaScript modular Programming", and explains how to put it into practice. Although this is not a beginner's tutorial, you can understand just a little bit about the basic syntax of JavaScript.

First, the original wording

A module is a set of methods for implementing a particular function.

Just put the different functions (and the variables of the record state) simply together, even a module.

function M1 () {
//...
}
    
function m2 () {
//...
}

The above function m1 () and M2 () to form a module. When used, call directly on the line.

The disadvantage of this approach is obvious: "pollution" of the global variable, can not guarantee that no variable name conflicts with other modules, and module members do not see a direct relationship.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

Related Article

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.