JS模块化库seajs体验
seajs
http://seajs.org/docs/en.html#intro
https://github.com/seajs/seajs/releases
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 CMD specification,as the Node.js 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 test cases, 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
http://wiki.commonjs.org/wiki/Modules/1.1.1
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规范:
http://www.requirejs.org/docs/api.html#funcmodule
//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();
}
}
);
实验
https://github.com/fanqingsong/code-snippet/tree/master/web/seajs_demo
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,更加直接,使用更加简单。
JS模块化库seajs体验的更多相关文章
- Js模块化开发--seajs和gruntJs
1.Seajs库 解决开发中的冲突依赖等问题,提供代码可维护性. SeaJS 是由玉伯开发的一个遵循 CommonJS 规范的模块加载框架,可用来轻松愉悦地加载任意 JavaScript 模块和css ...
- JS模块化规范CMD之SeaJS
1. 在接触规范之前,我们用模块化来封装代码大多为如下: ;(function (形参模块名, 依赖项, 依赖项) { // 通过 形参模块名 修改模块 window.模块名 = 形参模块名 })(w ...
- JS模块化开发:使用SeaJs高效构建页面
一.扯淡部分 很久很久以前,也就是刚开始接触前端的那会儿,脑袋里压根没有什么架构.重构.性能这些概念,天真地以为前端===好看的页面,甚至把js都划分到除了用来写一些美美的特效别无它用的阴暗角落里,就 ...
- JS模块化开发(三)——seaJs+grunt
1.seaJs直接构建存在的问题 由于模块之间的依赖require引用的是模块名,当多个js模块被合并成一个时,会由于找不到模块名而报错 2.seaJs+grunt开发 用到的插件:grunt-cmd ...
- js模块化/js模块加载器/js模块打包器
之前对这几个概念一直记得很模糊,也无法用自己的语言表达出来,今天看了大神的文章,尝试根据自己的理解总结一下,算是一篇读后感. 大神的文章:http://www.css88.com/archives/7 ...
- js模块化AMD、CMD、ES6
AMD CMD ES6模块化 各个模块化规范对比理解 一.AMD 在上一篇js模块化入门与commonjs解析与应用中详细的解析了关于commonjs模块化规范,commonjs采用的用同步加载方式, ...
- 从273二手车的M站点初探js模块化编程
前言 这几天在看273M站点时被他们的页面交互方式所吸引,他们的首页是采用三次加载+分页的方式.也就说分为大分页和小分页两种交互.大分页就是通过分页按钮来操作,小分页是通过下拉(向下滑动)时异步加载数 ...
- js模块化历程
这是一篇关于js模块化历程的长长的流水账,记录js模块化思想的诞生与变迁,展望ES6模块化标准的未来.经历过这段历史的人或许会感到沧桑,没经历过的人也应该知道这段历史. 无模块时代 在ajax还未提出 ...
- AMD and CMD are dead之js模块化黑魔法
var define, require, define2, require2; typeof JSON != "object" && (JSON = {}), fu ...
随机推荐
- HttpLuaModule 获取Get和Post参数
Get方式: local id = tostring(ngx.var.arg_id) local type = tostring(ngx.var.arg_type) Post方式: ngx.req.r ...
- BZOJ2330 糖果题解 查分约束
BZOJ 2330 糖果题解 差分约束系统 + SPFA 题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2330 Description ...
- FS210开发板上Qt4.7.0移植过程
作者:冯老师,华清远见嵌入式学院讲师. 1. 搭建Qt开发环境平台 1.开发环境:ubuntu 12.04 2.交叉编译链:arm-cortex_a8-linux-gnueabi 3.开发板:FS21 ...
- Java_过滤字符串中非汉子的内容
/** * 去除“第”之前的所有非汉字内容 */ private String clearNotChinese(String buff){ String tmpString =buff.replace ...
- 对GitHub的认识
Github创建于2008年被市场研究公司Forrester称作开发者的Facebook .作为开源代码库以及版本控制系统,Github拥有140多万开发者用户.随着越来越多的应用程序转移到了云上,G ...
- 去掉tppabs冗余代码,怎样批量去掉tppabs代码
去掉tppabs冗余代码,怎样批量去掉tppabs代码 刚用teleport pro拉了一个整站到本地 所有的超链都被强行加了一句tppabs=" 就玩了一把dw的替换功能 查找范围:整 ...
- javascrit2.0完全参考手册(第二版) 第1章第1节 在XHTML文档中增加javascript
通常,向文档中增加script脚本使用<script>元素,在HTML中增加脚本的方式有4中: (1)放到<script></script>块中: (2)<s ...
- Jenkins 2.7.3 LTS 发布
更新如下: Stop A/B testing of the remoting JNLP3 protocol due to the known issues. The protocol can be e ...
- 利用MetaWeblog API实现XMLRPC写博客功能
Windows Live Writer是一款小巧的写博客的工具,非常方便,甚至网上看到过有的评论称Live Writer是一款最不像微软产品的微软产品. Writer支持MSN Spaces以及Wor ...
- HTML 5 服务器发送事件
接收 Server-Sent 事件通知 EventSource 对象用于接收服务器发送事件通知: 实例 var source=new EventSource("demo_sse.php&qu ...