Skip to content

Instantly share code, notes, and snippets.

@baobao12356
Forked from ufologist/app.js
Created July 12, 2017 10:38
Show Gist options
  • Select an option

  • Save baobao12356/3dfc4444864bee22b1ab7a8e867612f4 to your computer and use it in GitHub Desktop.

Select an option

Save baobao12356/3dfc4444864bee22b1ab7a8e867612f4 to your computer and use it in GitHub Desktop.

Revisions

  1. @ufologist ufologist created this gist Jun 20, 2013.
    3 changes: 3 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    seajs.use('./js/main', function(main) {
    main.hello();
    });
    24 changes: 24 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <!DOCTYPE html>
    <html>
    <head>
    <title>Hello SeaJS boilerplate</title>
    <meta charset="utf-8" />
    </head>
    <body>
    <h1>SeaJS load module mechanism</h1>
    <p>Open your console</p>
    <ol>
    <li>require module: main</li>
    <li>require module: mod1</li>
    <li>hello mod1</li>
    <li>require module: mod2</li>
    <li>hello mod2</li>
    <li>hello main</li>
    </ol>
    <h2>Conclusion</h2>
    <p>SeaJS execute modules as <strong>LAZY</strong> as possible(SeaJS只会在真正需要使用[依赖]模块时才执行该模块)</p>
    <p>SeaJS async load modules, but execute them accordance with the order in your code(SeaJS是异步加载模块的没错, 但执行模块的顺序也是严格按照模块在代码中出现(require)的顺序, 这样才更符合逻辑吧! 你说呢, RequireJS?)</p>
    <p>Test with SeaJS 2.0.0</p>
    <script data-main="./js/app.js" src="lib/sea.js"></script>
    </body>
    </html>
    14 changes: 14 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    define(function(require, exports, module) {
    console.log('require module: main');

    var mod1 = require('./mod1');
    mod1.hello();
    var mod2 = require('./mod2');
    mod2.hello();

    return {
    hello: function() {
    console.log('hello main');
    }
    };
    });
    9 changes: 9 additions & 0 deletions mod1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    define(function(require, exports, module) {
    console.log('require module: mod1');

    return {
    hello: function() {
    console.log("hello mod1");
    }
    };
    });
    9 changes: 9 additions & 0 deletions mod2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    define(function(require, exports, module) {
    console.log('require module: mod2');

    return {
    hello: function() {
    console.log("hello mod2");
    }
    };
    });