(7 interfaces are most commonly used)
First, Seajs.config: Used to configure the sea.js.
seajs.config ({ // set path, easy to call paths across directories : {' Arale ': ' https:// A.alipayobjects.com/arale ', ' jquery ': ' Https://a.alipayobjects.com/jquery ' }, // set aliases for easy invocation alias: { ' class ': ' Arale/class/1.0.0/class ', ' jquery ': ' jquery/jquery/ 1.10.1/jquery ' }});
Second, Seajs.use: used to load one or more modules in the page.
// load a module seajs.use ('./a '); // load a module and execute a callback when the load is complete function (a) { a.dosomething ();}); // load multiple modules, execute callbacks when loading is complete function (A, b) { a.dosomething (); B.dosomething ();});
Third, define: Used to define the module. Sea.js respected a module of a file, following a unified notation:
Define (function(require, exports, module) { // Modules code });
You can also specify the module ID and dependencies manually.
require
, exports
and module
three parameters can be omitted as appropriate, as follows:
1)require: require
the interface used to obtain the specified module.
Define (function(require) { // Gets the interface of module a var a = require ('./a ') ); // method of calling module a a.dosomething ();});
Note that require
only string literals are accepted as arguments,
2)Require.async: Used to asynchronously load one or more modules inside the module.
Define (function(require) { // asynchronously loads a module that executes the callback function when loading is complete (b) { b.dosomething (); }); // asynchronously loads multiple modules and executes callbacks when loading is complete function (c, D) { c.dosomething (); D.dosomething (); } );
3) Exports: Used to provide external interface inside the module.
Define (function(require, exports) { // externally supplied foo attribute exports.foo = ' Bar ' ; // dosomething Methods for external delivery function () {};});
4) Module.exports: exports
Similar, used to provide external interfaces within the module.
Define (function(require, exports, module) { // externally supplied interface module.exports = { ' a ', function() {}; };});
module.exports
with exports
the difference .
Sea.js Learning 2--sea.js API Quick Reference