Sea.js Learning 2--sea.js API Quick Reference

Source: Internet
Author: User

(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.exportswith exports the difference .

Sea.js Learning 2--sea.js API Quick Reference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.