On the modularization development of JavaScript

Source: Internet
Author: User

//immediately-invoked fuction expression iife;(function(ARG) {returnsomething;}) (ARG);//The second type of notation!function(ARG) {} (arg);//The Third kind of wording(function(ARG) {} (ARG)); //eg to access Moduleproperty Modulemethod    varModule = (function(){        varmy ={}, privatevariable= 1; functionPrivatemethod () {} my. Moduleproperty= 1; My.modulemethod=function(){        }; returnmy; }());//EG2    varModule = (function(){        varmy ={}, privatevariable= 1; functionPrivatemethod () {} my={moduleproperty:1; Modulemethod:function(){            }        }        returnmy;    }()); //use object Direct amount to express    varmy ={moduleproperty:1; Modulemethod:function(){            }        }; //returns a function such as jquery    varCat = (function(){        //Private Members        return function(name) { This. Name =name;  This. Bark =function(){};    }    }()); varTomcat =NewCat ("Tom"); Tomcat.bark ();//    varmodule = (function(){        varx = 1; functionF1 () {}functionF2 () {}return{publicmethod:f1, publicmethod:f2}}    ()); //Extended    varModule = (function(my) {My.anothermothod=function(){        }; returnmy;    } (Module)); //loosely coupled extensions if you don't define a module or do not care about the loading order     varModule = (function(my) {My.anothermothod=function(){        }; returnmy; } (Module|| {} )); //tightly coupled extensions are defined, and extended over previous methods on a prior basis      varModule = (function(my) {varOldmothod =My.modulemethod; My.modulemethod=function(){              //Method Overloading          }; returnmy;     } (Module)); //cloning and inheritance a     varModule_two = (function(old) {//         varmy ={}, key;  for(KeyinchOld ) {             if(Old.hasownpropery (key)) {My[key]=Old[key]}} varSupermethod =Old.modulemethod; My.modulemethod=function(){             //rewrite             //Supermethod         };     } (Module)); //b Create (old);     varModule_two = (function(old) {varmy =Create (old); varSupermethod =Old.modulemethod; My.modulemethod=function(){             //rewrite             //Supermethod         }; } (Module));

On the modularization development of JavaScript

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.