Home  >  Article  >  Web Front-end  >  What file is seajs?

What file is seajs?

anonymity
anonymityOriginal
2019-05-28 15:37:202793browse

What is seaJS?

Similar to requireJS, seaJS is also a JS framework written in JavaScript. Its main function is to load JavaScript and other files according to different dependencies. It can be simply understood as loading JS files. It is very suitable for use in browsers. It can ensure that the current JS file is loaded after the dependent JS files are loaded. This ensures the sequential loading order of each JS file in projects that use a large number of JS files, ensuring that avoidance In the past, due to some reasons, a file was slow to load and other fast-loading files needed to rely on some of its functions and a certain function or a certain variable could not be found. This is very useful and is also the main reason for seaJS (complying with CMD) The value lies in it; but it is different from requireJS (complying with AMD specifications).

What file is seajs?

Quickly brief knowledge points:

1. seajs.config({...}); //Used to configure Sea.js for configuration.

2. seajs.use(['a','b'],function(a,b){...}); //Used to load one or more modules in the page.

3. define(function(require, exports, module){...}); //Used to define modules. Sea.js recommends one module and one file, and follows a unified writing method:

4. require(function(require){var a = require("xModule"); ... }); //require is used Get the interface of the specified module.

5. require.async, //Used to load one or more modules asynchronously inside the module. For example:

define(function(require){
    require.async(['aModule','bModule'],function(a,b){  // 异步加载多个模块,在加载完成时,执行回调
    a.func();
    b.func();
    })    
});

6, exports, //Used to provide external interfaces within the module. For example:

define(function(require, exports){
    exports.varName01 = 'varValue';  // 对外提供 varName01 属性    
    exports.funName01 = function(p1,p2){  // 对外提供 funName01 方法
    ....
    }       
});

7. module.exports, similar to exports, is used to provide external interfaces within the module. For example:

define(function(require, exports, module) {  
  module.exports = {  // 对外提供接口
    name: 'a',
    doSomething: function() {...};
  };
});

The above 7 interfaces are the most commonly used and should be kept in mind.

Okay, that’s it for the brief introduction. Let’s look at a practical example:

The design requirement of this example is that the hellowMain.js file depends on hellow.js, and jQuery is loaded into the project as a backup. Only after the dependent files are loaded can the business JS code initialization work be carried out. ;

First look at the example file directory structure:

//file of folder structure

//---------------- -------------------------------------

//SeaJS project directory The general format is as follows, such as the structure under userExample01

userExample01

|-----sea-modules

|--sea.js and other framework JS files

|-----app

|-----app

|----*.html Page html file

|-----static

|--| ---hellow

|---*.js/*.css

###//----------------------------- ----------------------------------###

The above is the detailed content of What file is seajs?. For more information, please follow other related articles on the PHP Chinese website!

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