1. Introduction
Seajs, a web module loading framework, pursues simple and natural code writing and organization methods,: follows CMD specifications, modular JS code. The automatic loading and concise and clear configuration of dependencies can allow programmers to focus more on coding.
2. Pros and cons
advantage:
1). Improve maintainability.
2). Modular programming.
3). Dynamic loading, front-end performance optimization
shortcoming:
1). The learning documents are relatively small and confusing, which will change the team's writing habits of using JS and must use modular programming.
2). Not suitable for the current situation of the team, with more JS files but few changes, and the advantages of dynamic loading and modularity are not obvious.
3). It is necessary to use SPM tools, JS packaging and management tools.
2.What are CMD and AMD?
Asynchronous Module Definition (AMD) is the abbreviation of Asynchronous Module Definition and is the standardized output of RequireJS for module definition during the promotion process.
Common Module Definition (CMD) is the abbreviation of Common Module Definition and is the standardized output of SeaJS's module definition during the promotion process.
RequireJS and SeaJS are both representatives of modular frameworks. AMD and CMD are their own ways to define modularity, which are similar, mainly because of the different code styles and APIs.
3. How to use it?
<script>
//Configure the js path
({
alias:{
"jquery":"../examples-master/sea-modules/jquery/jquery/1.10.1/"
}
});
//Loading the module
('../js/seajs/init',function($){
$("#test_div").click(function(){alert(1);});
});
</script>
//
define(function(require,exports,module){
var $ = require('jquery');
return $;
});