Sea.js Manual & Documentation


Table of Contents


Quick References

This page lists the mostly used methods of SeaJS. In most cases, these methods are enough for module development.

seajs.use seajs.use

seajs.use('./a');

seajs.use('./a', function(a) {
  a.doSomething();
});

seajs.use(['./a', './b'], function(a, b) {
  a.doSomething();
  b.doSomething();
});

seajs.config seajs.config

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 define

define(function(require, exports, module) {

  // The module code goes here

});

require require

define(function(require) {
  var a = require('./a');
  a.doSomething();
});

require.async require.async

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
  });
});

exports exports

define(function(require, exports) {
  // snip...
  exports.foo = 'bar';
  exports.doSomething = function() {};
});

module.exports module.exports

define(function(require, exports, module) {
  // snip...
  module.exports = {
    name: 'a',
    doSomething: function() {};
  };
});