Javascript modularization simple parsing _ javascript tips-js tutorial

Source: Internet
Author: User
Tags define definition
This article mainly targets javascript modularization for simple parsing. How to Write a module and load the module on the page, interested friends can refer to this article to explain the modularization of javascript. The specific content is as follows:

AMDThis is the standardized output defined by RequireJS in the promotion process.

Asynchronously load the module, depending on the front, and execute it in advance.
Define definition module define (['require ', 'foo'], function () {return });
Require loading module (dependent on the front) require (['foo', 'bar'], function (foo, bar ){});

CMDThis is the standardized output defined by SeaJS in the promotion process.

Define defines exports to export define (function (require, exports, module) {}); the module stores some objects on the current module.
Directly introduce require (./. Require. async asynchronous introduction.
Synchronous loading with nearby dependencies and delayed execution.

SeaJS Application

Official Entry Example: http://seajs.org/docs/#quick-start

How to Write a SeaJS module?

// All modules use define to define (function (require, exports, module) {// introduce the dependency var $ = require ('jquery ') through require '); var Spinning = require ('. /spinning '); // provides the interface exports through exports. doSomething =... // or use module. exports provides the entire interface module. exports = ...});

In the pageLoad Module

// At the end of hello.html, use the script to introduce sea. after js, there is a piece of configuration code: // seajs simple configuration seajs. config ({base :".. /sea-modules/", alias: {" jquery ":" jquery/1.10.1/jquery. js? 1.1.23 "}) // load the entry module seajs. use (" ../static/hello/src/main ")

The above is a brief introduction to javascript modularization, hoping to help you learn about javascript modularization.

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.