Javascript 類、命名空間、代碼組織代碼
更新時間:2011年07月31日 23:07:20 作者:
Javascript 類、命名空間、代碼組織代碼,學(xué)習(xí)js的朋友可以參考下。
復(fù)制代碼 代碼如下:
$(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;
}
}
}
};
相關(guān)文章
微信小程序MUI側(cè)滑導(dǎo)航菜單示例(Popup彈出式,左側(cè)滑動,右側(cè)不動)
這篇文章主要介紹了微信小程序MUI側(cè)滑導(dǎo)航菜單,結(jié)合實(shí)例形式分析了微信小程序Popup彈出式,左側(cè)滑動,右側(cè)不動菜單功能相關(guān)實(shí)現(xiàn)技巧與注意事項,需要的朋友可以參考下2019-01-01利用Echarts實(shí)現(xiàn)圖例顯示百分比效果
EChart開源來自百度商業(yè)前端數(shù)據(jù)可視化團(tuán)隊,基于html5?Canvas,是一個純Javascript圖表庫,提供直觀,生動,可交互,可個性化定制的數(shù)據(jù)可視化圖表。本文將利用EChart實(shí)現(xiàn)圖例中顯示百分比的效果,感興趣的可以學(xué)習(xí)一下2022-03-03JS操作XML實(shí)例總結(jié)(加載與解析XML文件、字符串)
這篇文章主要介紹了JS操作XML的方法,結(jié)合實(shí)例形式總結(jié)分析了JavaScript加載與解析XML文件及字符串的相關(guān)技巧,需要的朋友可以參考下2015-12-12小程序通過小程序云實(shí)現(xiàn)微信支付功能實(shí)例
本文主要介紹了小程序通過小程序云實(shí)現(xiàn)微信支付功能實(shí)例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-07-07