前提
JS采用面向对象的编写方法
每个JS文件只有一个公有 function 对象 且对象名与文件名相同
/**
* JS对象 面向对象引入 方法
* 参数 由路径.对象名 组成 例如 com.zwm.table.BaseTable 表示引入 com/zwm/table/BaseTable.js
* 可以自动判断该文件是否已经引入 如果已经存在,刚不再引入
* @param {Object} js 对象名
* @author zwm
* @date 2008-01-10
*/
function include(js){
//JS文件名 对象名
var name =js.substring(js.lastIndexOf(".")+1);
//文件路径 包名
var path = js.substring(0,js.lastIndexOf("."));
while(path.indexOf(".") >-1 ){
path = path.replace(".","/");
}
//向页面输出语句
var file = "<script src='"+path+"/"+name+".js'></script>";
try {
if(typeof(eval(name)) == "function"){
/**该JS已经被引入,不需要再引入**/
}else{
//引入该JS
document.writeln(file);
}
}catch(e){
document.writeln(file);
}
}