Seajs Getting Started with

Source: Internet
Author: User

The use of sea.js for modular development can also bring many benefits:

    1. Version management of the module . With the configuration of aliases, it is easy to implement the version management of the module with the build tool.

    2. improved maintainability . Modularity allows each file to have a single responsibility and is very useful for code maintenance. Sea.js also provides NoCache, debug and other plug-ins, with on-line debugging and other functions, can be more obvious to improve efficiency.

    3. Front-end performance optimization . Sea.js is useful for page performance by loading modules asynchronously. Sea.js also provides combo, flush and other plug-ins, with the service side, can be good for page performance tuning.

    4. cross-Environment shared module . The CMD module definition specification is very similar to node. JS's module specification. With the Sea.js node. js version, it is easy to implement modules across server and browser sharing.


SEAJS official website
Sea.js 2.3. version 0 Download

SEAJS File Structure:

Complete the above steps, and then demonstrate a simple way to use the SEAJS
First step: Defineused to define the module. Sea.js respected a module of a file, following a unified notation:
Define (function (require,exports,module) {      var _msg = ' not set msg! ';  exports.setmsg = function (msg) {  _msg = msg;  };    Exports.getmsg = function () {  return _msg;    };});

The first parameter: require is used to get the specified interface, note that require only accepts strings as arguments directlysecond parameter: Exports is used to provide an external interface to the inside of a moduleThird parameter: module is similar to exports to provide external interfaces inside the module
Step Two:when the module is defined, configure the module that you just configured into SEAJS. Seajs.config
Seajs.config ({    alias:{         ' init ': "Modul/init.js"        }});

Init indicates that the module ID is custom, "modul/init.js" is the relative path of the module can omit JS, note: The absolute path of the module is Seajs-2.3.0/dist/modul/init.js
Seajs.use

Used to load one or more modules in a page.

Seajs.use ("Init", function (init) {//Set value init.setmsg (' Hello World ');     Alert (init.getmsg ());});

Effect:


  code for the HTML page:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >


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.