Javascript 类、命名空间、代码组织代码分享


代码如下:
$(function () {
pageJs.urls = [
‘/’, ‘Index’,
];
pageJs.run();
});
//the functions include html elements. Ajax function also can be put here.
var Common = {
init: function () {
alert(‘Common’);
}
};
//url–pages
var Index = {
init: function () {
Common.init();
this.test();
this.test2();
alert(location.pathname);
},
test: function () {
alert(‘test’);
}
};
Index.test2 = function () {
Index.test();
alert(‘test2’);
}
//should be remove to other js file, and load before this file.
//the functions don’t include any html elements.
var Utils = {
debug: function () {
}
};
var pageJs = {
urls: [],
run: function () {
var urls = this.urls;
alert(urls.length);
if ((urls.length % 2) != 0) {
throw “urls error”;
}
var len = urls.length / 2;
for (var i = 0; i <= len; i = i + 2) {
var pattern = new RegExp(urls[i], ‘i’);
if (pattern.test(location.pathname)) {
eval(urls[i + 1] + “.init()”);
break;
}
}
}
};

—-想了解更多的linux相关异常处理怎么解决关注<计算机技术网(www.ctvol.com)!!>



本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/jspttutorial/65286.html

(0)
上一篇 2020年4月11日
下一篇 2020年4月11日

精彩推荐