博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JS模块化库seajs体验
阅读量:5060 次
发布时间:2019-06-12

本文共 2266 字,大约阅读时间需要 7 分钟。

seajs

Extremely simple experience of modular development

 

Why use Sea.js ?

Sea.js's pursuit of a simple, natural coding and organization,has the following key aspects:

  • The definition of a module specification is simple and friendly:Sea.js follow the specification,as the module style.
  • Natural and intuitive code organization:Automatically load dependence, configuration is simple and clear,so that we can more enjoy coding.

Sea.js provides common plug-ins,they are very helpful for the development of debugging and performance optimization,and has a rich extensible interface.

模块的声明非常 简单 和 友好。

自然和直觉性的代码组织方式。自动依赖下载 和 配置简单明了。

 

兼容性:

Compatibility

Sea.js has perfect , compatible with all major browsers:

Chrome 3+         ✔Firefox 2+        ✔Safari 3.2+       ✔Opera 10+         ✔IE 5.5+           ✔

Sea.js can be run in Mobile terminal,including Hybrid Mode App. In theory, Sea.js can be run in any browser.

 

 

CMD

CMD规范模块定义格式

//Inside b.js:define(function(require, exports, module) {    //If "a" has used exports, then we have a real    //object reference here. However, we cannot use    //any of "a"'s properties until after "b" returns a value.    var a = require("a");    exports.foo = function () {        return a.bar();    };});

 

AMD规范:

//Inside b.js:define(["require", "a"],    function(require, a) {        //"a" in this case will be null if "a" also asked for "b",        //a circular dependency.        return function(title) {            return require("a").doSomething();        }    });

 

实验

 

one.js

//Inside one.js:

define(function(require, exports, module) {
      var two = require('./two.js');

      exports.sayHello = function() {

        console.log('one module called');
      };

      exports.callTwo = function() {

        two.sayHello();
      };
    }
);

two.js

//Inside two.js:

define(function(require, exports, module) {
      exports.sayHello = function() {
        console.log('two module called');
      };
    }
);

demo.html

<html>

<head>
        <!--This sets the baseUrl to the "scripts" directory, and
            loads a script that will have a module ID of 'main'-->
        <script src="./sea.js"></script>
        <style>

        </style>

        <script>
        seajs.use('one', function(one) {
          one.sayHello();
          one.callTwo();
        });
        </script>
</head>
<body>
        <h1>hello world!</h1>
</body>
</html>

相比requirejs,更加直接,使用更加简单。

转载于:https://www.cnblogs.com/lightsong/p/5582366.html

你可能感兴趣的文章
硬件笔记之Thinkpad T470P更换2K屏幕
查看>>
【知识库】-数据库_MySQL 的七种 join
查看>>
iOS开发——缩放图片
查看>>
HTTP之URL的快捷方式
查看>>
满世界都是图论
查看>>
配置链路聚合中极小错误——失之毫厘谬以千里
查看>>
代码整洁
查看>>
蓝桥杯-分小组-java
查看>>
Java基础--面向对象编程1(类与对象)
查看>>
Android Toast
查看>>
iOS开发UI篇—Quartz2D使用(绘制基本图形)
查看>>
docker固定IP地址重启不变
查看>>
桌面图标修复||桌面图标不正常
查看>>
JavaScript基础(四)关于对象及JSON
查看>>
关于js sort排序方法
查看>>
JAVA面试常见问题之Redis篇
查看>>
javascript:二叉搜索树 实现
查看>>
网络爬虫Heritrix源码分析(一) 包介绍
查看>>
__int128的实现
查看>>
Problem - 1118B - Codeforces(Tanya and Candies)
查看>>