Home >Web Front-end >JS Tutorial >Seajs study notes_Seajs

Seajs study notes_Seajs

WBOY
WBOYOriginal
2016-05-16 16:57:15950browse

1. Introduction

Seajs, a Web module loading framework, pursues a simple and natural way of writing and organizing code: Sea.js follows the CMD specification and modularizes JS code. Automatic loading of dependencies and concise and clear configuration allow programmers to focus more on coding.

2. Advantages and disadvantages

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

Disadvantages:
1). The learning documents are sparse and confusing, which will change the team’s writing habits 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. The advantages of dynamic loading and modularization are not obvious.
3). Requires the use of SPM tools, JS packaging and management tools.

2. What are CMD and AMD?

Asynchronous Module Definition (AMD) is the abbreviation of Asynchronous Module Definition, which is the standardized output of module definition during the promotion process of RequireJS.
Common Module Definition (CMD) is the abbreviation of Common Module Definition, which is the standardized output of module definition during the promotion process of SeaJS.
RequireJS and SeaJS are both representatives of modular frameworks. AMD and CMD are their respective ways of defining modularity. They are similar, mainly in coding style and API.

3. How to use?

Copy code The code is as follows:

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

Copy code The code is as follows:

//init.js
define(function(require,exports,module){
var $ = require('jquery');
return $;
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn