源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-07-16 23:07 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Javascript 类、命名空间、代码组织代码
[u]复制代码[/u] 代码如下:
$(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; } } } };
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部