Seajs is what and sea.js origin, features and advantages _seajs

Source: Internet
Author: User
Tags require

1.SEAJS Introduction

Seajs, a Web module loading framework, the pursuit of simple, natural code writing and organization,: Sea.js Follow the CMD specification, modular JS code. Relying on automatic loading, simple and clear configuration, allows programmers to focus more on coding.

2.Seajs Advantages and disadvantages

Advantages:
1). Improve maintainability.
(2). Modular programming.
3). Dynamic loading, front-end performance optimization

Disadvantages:
1. Learning less and confusing documents will change the writing habits of the team using JS and must be programmed using modularity.
2). Not very suitable for the current situation of the team, more JS file but less changes, dynamic loading advantages and modularity advantage is not obvious.
3. Need to support the use of SPM tools, JS packaging and management tools.

2. What is cmd and AMD?

Asynchronous module definition (AMD) is the abbreviation of Asynchronous module definition, and it is the normalized output of requirejs in the process of generalization.
Universal module definition (CMD) is the abbreviation of Common module definition, and it is the normalized output of seajs in the process of generalization.
Both Requirejs and SEAJS are representatives of modular frameworks, AMD and CMD, which are their respective ways of defining modularity, the same as the code style and API.

3.Seajs How to use?

A piece of code to teach novice at a glance, Quick start!

The code is as follows: <script src= ". /js/examples-master/sea-modules/seajs/seajs/2.1.1/sea.js "></script>

<script>
  //Configure JS path
 seajs.config ({
  alias:{
   "jquery": ". /examples-master/sea-modules/jquery/jquery/1.10.1/jquery.js "
  }
 });
  Load Module
 seajs.use (' .... /js/seajs/init ', function ($) {
  $ ("#test_div"). Click (function () {alert (1);});
</script>

The code is as follows:

Init.js
define (function (require,exports,module) {
var $ = require (' jquery ');
return $;
});

Seajs is so simple, quick to learn it!

Origin:

In the software development process, modular programming ideas have become accustomed to, modular programming not only for the development team to bring efficiency benefits, but also to develop the project or product maintenance costs greatly reduced.
Then, in the Web development process, JS scripting language has become indispensable, through the JS scripting language can bring more comfortable man-machine interaction and user experience. However, the use of JS script will also have the confusion of reference dependencies, then JS scripting language Modular Thinking will be widely recognized, in such a context, Taobao front-end engineers Yuber brought Seajs scripting language, so that modular programming ideas into the world of JS script.

Features:

Seajs is a JavaScript module loading framework that follows the COMMONJS specification, which enables the modular development and loading mechanism of JavaScript. Unlike JavaScript frameworks such as jquery, SEAJS does not extend the encapsulation language feature, but simply implements JavaScript modularity and loading by module. The main purpose of SEAJS is to make JavaScript development modular and easy to load, freeing up front-end engineers from heavy JavaScript files and object-dependency processing, and focusing on the logic of the code itself. Seajs can be seamlessly integrated with a framework such as jquery. Using SEAJS can improve the readability and clarity of JavaScript code, solve the problem of dependency confusion and code entanglement in JavaScript programming, and facilitate the writing and maintenance of code. The
Seajs itself is developed by following the kiss (Keep It simple, stupid) concept, which itself has only a single-digit API, so it is no pressure to learn. In the process of learning seajs, you can feel the essence of kiss principle--only do one thing, do one thing well.

Advantage: Look at the SEAJS advantage in one example,

Traditional mode:

var m1={
run:function () {
alert (' M1 ');
M2.run ();
}
 
var m2={
 
run:function () {
alert (' M2 ');
}
 
<script src= "./m2.js" ></script>
<script src= "./m1.js" ></script>

After using Seajs:

Init.js
define (function (Require, exports, module) = {
 
var m1=require (' M1 ');
 
Exports.init=function () {
m1.run ();
}
});
 
M1.js
define (function (require,exports,module) ={
var m2=require (' M2 ');
 
Exports.run=function () {
alert (' M1 ');
M2.run ();
}
);
 
Define (function (require,exports,module) ={
exports.run=function () {
alert (' M2 ');
}
});

<script src= "./sea.js" ></script>
<script>
 seajs.use ('./init ', function (init) {
  Init.init ();
 });
</script>

With two simple examples, it is clear that the modularity of the code after using Seajs, and that only one./sea.js file is referenced in the HTML page and only the Init can be invoked, and the logic implemented after the specific init is transparent to the user.

Through this blog to be able to understand the Seajs scripting language, the following article describes the use of Seajs writing module.

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.