Javascript class, namespace, Code Organization Code _ javascript skills

Source: Internet
Author: User
Javascript class, namespace, Code Organization Code. For details about js learning, refer. The Code is as follows:


$ (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 ');
}
// Shocould 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;
}
}
}
};

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.