Seajs Study Notes
This article mainly introduces Seajs's knowledge and learning experience. It is suitable for those who are new to SeaJS. For more information, see
1. Introduction
Seajs is a Web module loading framework that pursues simple and natural code writing and organization methods. Sea. js complies with CMD specifications and is modularized with JS Code. The automatic dependency loading and configuration are concise and clear, allowing programmers to focus more on coding.
2. Advantages and Disadvantages
Advantages:
1). improve maintainability.
2). Modular programming.
3). Dynamic Loading and front-end performance optimization
Disadvantages:
1). Learning documents are less complex and confusing. This will change the team's JS writing habits and requires Modular programming.
2). It is not suitable for the current situation of the team. There are many JS files but few changes, and the advantage of dynamic loading and modularity is not obvious.
3). The SPM and JS packaging and management tools must be used together.
2. What are CMD and AMD?
Asynchronous Module Definition (AMD) is short for Asynchronous Module Definition, and is the standardized output of modules defined by RequireJS during the promotion process.
The general Module Definition (CMD) is the abbreviation of the Common Module Definition. It is the standardized output of the Module Definition in SeaJS during the promotion process.
Both RequireJS and SeaJS are representative of the modular framework. AMD and CMD are different in code style and API.
3. How to use it?
The Code is as follows: <script src = "../js/examples-master/sea-modules/seajs/2.1.1/sea. js"> </script>
<Script>
// Configure the js path
Seajs. config ({
Alias :{
"Jquery": "../examples-master/sea-modules/jquery/1.10.1/jquery. js"
}
});
// Load the 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 $;
});