Seajs 使用总结
来源:互联网 发布:md5加密 java代码 编辑:程序博客网 时间:2024/06/08 11:58
1、定义一个js
define(dunction(require,exports,module){
});
require:主要功能是访问其他模块提供的API,调用该模块的方法,
For example:defune(function(require){
var test=require('./test');
test.do();// 调用了test中的do方法
});
exports: 主要功能是提供模块的API,定义一个对外的接口。
define(function(require,exports,module){
function Darw(){
this.id=1;
this.width=10;
this.text="深度";
}
module.exports=Darw;
});
return 也可以实现这一样的功能
define(function(require,exports,module){
return {doSomething:function(){ }};
});
module:存储模块的元信息,包含如下信息:
module.id 当前模块的唯一标示
module.Dependencies 依赖列表
module.exports 可以对export参数进行自定义{没明白?}
module.constructor 为所有的module参数对象添加一些公用属性或方法。
seajs.use('./example',function(example){
example.sayHello();
});
第一个参数就是指定的一个模块,
第二个参数是一个函数函数的参数就是一个模块的实例。
2、引入第三方框架jQuery
define(function(){
/* jQuery 源码 */
return $.noConflict();
});
//应用方法
var $=require("jquery");
$("#id").click(.....);
3、异步的加载多个模块
requrie.async(['./c','./d'],function(c,d){
c.do();
d.do();
});
4、别名配置
添加一个js文件config.js
内容可以为
seajs.config({
// Enable plugins
plugins : [ 'shim' ],
// Configure alias
alias : {
'jquery' : {
src : 'lib/jquery-1.8.2.min.js',
exports : 'jQuery'
},
'jquery.contextMenu' : {
src : 'lib/jQcontextMenu/jquery.contextMenu.js',
deps : [ 'jquery' ]
},
});
在引入模块的时候就可以使用别名了
5、在页面用引入
<script src="webDraw/js/seajs/sea.js"
id="seajsnode"
data-config="config.js"
data-main="init.js"></script>
- Seajs 使用总结
- 前端框架 seajs 使用总结
- 前端框架 seajs 使用总结
- seajs打包部署工具spm的使用总结
- seajs打包部署工具spm的使用总结
- seajs打包部署工具spm的使用总结
- 使用 gulp-seajs-combo 合并 seajs 模块
- SeaJS使用教程
- seajs使用教程指南
- seajs使用注意点
- seajs 使用jquery插件
- SeaJS使用教程指南
- seajs 使用点滴
- seajs入门使用
- 使用 spm 和 SeaJS
- seajs使用插件问题
- seajs使用教程指南
- SeaJS使用详细教程
- 关于软件测试用例生成技术相关研究总结
- 运算符重载
- loadrunner 监控tomcat的代码
- 警察与小偷的实现之一客户端与服务端通信
- HDU 4453 Looploop(SplayTree)
- Seajs 使用总结
- 深入分析Linux内核源码
- 同一线程多次创建 的 线程资源释放问题在每个线程的一开始,用pthred_detach(pthread_self())来使自己detach掉
- Skynet网络模型
- scala implicit 隐式转换
- js 后缀数组求最大重复子串
- Boost智能指针——shared_ptr
- 苹果为何是Linux的最大竞争对手?
- jdbc 连接mysql数据库