Study notes for Seajs
- 2020-03-30 02:13:04
- OfStack
1. Introduction
Seajs, a Web module loading framework, the pursuit of simple, natural code writing and organization, : Sea. Js follows the CMD specification, modular js code. Dependencies are loaded automatically and configured cleanly, allowing programmers to focus more on coding.
2. The advantages and disadvantages of
Advantages:
1). Improve maintainability.
2). Modular programming.
3). Dynamic loading, front-end performance optimization
Disadvantages:
1). Learning documents are too few and messy, which will change the team's writing habit of using JS, and modular programming must be used.
2). It is not suitable for the current situation of the team. There are many JS files but few changes, and the advantages of dynamic loading and modularity are not obvious.
3). SPM tools and JS packaging and management tools should be used.
2. What are CMD and AMD?
Asynchronous Module Definition (AMD), short for the Asynchronous Module Definition, is the normalized output of the Module Definition from RequireJS's promotion.
The Common Module Definition (CMD) is an abbreviation of the Common Module Definition, which is the normalized output of SeaJS 'Module Definition during the promotion process.
RequireJS and SeaJS are both examples of modularity frameworks, while AMD and CMD are each defining modularity in a similar way, mainly in terms of code styles and apis.
3. How to use it?
<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>
//init.js
define(function(require,exports,module){
var $ = require('jquery');
return $;
});