标签:1.5 页面 turn html post html 4.01 class 导入 lis
使用 Sea.js 进行模块化开发还能够带来非常多优点:
模块的版本号管理。
通过别名等配置,配合构建工具,能够比較轻松地实现模块的版本号管理。
提高可维护性。模块化能够让每一个文件的职责单一,很有利于代码的维护。Sea.js 还提供了 nocache、debug 等插件,拥有在线调试等功能。能比較明显地提升效率。
前端性能优化。
Sea.js 通过异步载入模块,这对页面性能非常故意。
Sea.js 还提供了 combo、flush 等插件,配合服务端,能够非常好地对页面性能进行调优。
跨环境共享模块。
CMD 模块定义规范与 Node.js 的模块规范非常相近。通过 Sea.js 的 Node.js 版本号。能够非常方便实现模块的跨server和浏览器共享。
define(function(require,exports,module){
var _msg = ‘not set msg!‘;
exports.setMsg = function(msg){
_msg = msg;
};
exports.getMsg = function(){
return _msg;
};
});seajs.config({
alias:{
‘init‘:"modul/init.js"
}
});用来在页面中载入一个或多个模块。
seajs.use("init", function(init){
//设置值
init.setMsg(‘Hello World‘);
alert(init.getMsg());
});
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!-- 导入seajs-2.3.0这个文件 -->
<script type="text/javascript" src="seajs-2.3.0/dist/sea.js"></script>
<script type="text/javascript">
//配置seajs
seajs.config({
alias:{
‘init‘:"modul/init.js"
}
});
//使用seajs
seajs.use("init", function(init){
//设置值
init.setMsg(‘Hello World‘);
alert(init.getMsg());
});
</script>
</head>
<body>
<h1>Test seajs</h1>
</body>
</html>标签:1.5 页面 turn html post html 4.01 class 导入 lis
原文地址:http://www.cnblogs.com/zhchoutai/p/6888468.html