Seajs 2.3.0 getting started, seajs2.3.0

Source: Internet
Author: User

Seajs 2.3.0 getting started, seajs2.3.0

[Seajs]

A long time ago, I tried seajs many times. It may be because I am stupid or the documents and examples of seaj are too simple to start,

This time I made a website myself and reduced the http request when referencing multiple js files,

After searching for half a day, I found seajs + spm again. Okay, let's try again.


[Blog]

This blog post is very thorough and seems to have been written by seajs developers for reference. If this blog post can be understood, you don't have to read it any more,

Address: https://speakerdeck.com/lifesinger/seajs


[Getting started with dummies]

If you still can't understand it, let's take a look at it step by step.

Note:

My example is written using freemarker. If you don't know this, you need to rewrite it to html,

In fact, there is no difference, that is, the path needs to be changed. If you know, you can directly run tomcat.


[Demo01]

Demo01.ftl

<! DOCTYPE html> 

Demo01.js

// A js file in seajs is a module. The module definition defines define (function () {alert ('20140901 ');});

Running effect:


[Demo02]

Demo02.ftl

<! DOCTYPE html> 

Demo02.js

define(function(require, exports){exports.msg = '222';});

Running effect:


[Demo03]

Demo03.ftl

<! DOCTYPE html> 

Demo03.js

define(function(require, exports){var demo = require('./demo.js');var str = demo.getStr('test');exports.msg = 'the res is:' + str;});

Demo. js
define(function(require, exports){exports.getStr = function(ss){if(ss == '1'){return '111';}else{return '222';}};});

Running effect:


[Simple description]

Take demo03 for example:

1. Each js is a module and the definition must use define.

2. Each module has two parameters: require and exports.

3. require defines the module that this module depends on.

4. exports defines the external methods provided by this module to other modules. Other modules can call these methods after obtaining this module.

5. use the seajs. use module when using it.




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.