该页面列举了 SeaJS 中的常用 API。只要掌握这些方法,就可以娴熟地进行模块化开发。
seajs.use('./a'); seajs.use('./a', function(a) { a.doSomething(); }); seajs.use(['./a', './b'], function(a, b) { a.doSomething(); b.doSomething(); });
seajs.config({ alias: { 'es5-safe': 'es5-safe/0.9.2/es5-safe', 'json': 'json/1.0.1/json', 'jquery': 'jquery/1.7.1/jquery' }, preload: [ Function.prototype.bind ? '' : 'es5-safe', this.JSON ? '' : 'json' ] });
define(function(require, exports, module) { // The module code goes here });
define(function(require) { var a = require('./a'); a.doSomething(); });
define(function(require, exports, module) { // load one module require.async('./b', function(b) { b.doSomething(); }); // load multiple modules require.async(['./c', './d'], function(c, d) { // do something }); });
define(function(require, exports) { // snip... exports.foo = 'bar'; exports.doSomething = function() {}; });
define(function(require, exports, module) { // snip... module.exports = { name: 'a', doSomething: function() {}; }; });