Recently contacted some examples of JavaScript development, here to share with you:
Example: When we a team in the writing JS file, you write the JS code yourself can understand can also be maintained, but others want to your JS to expand, if all in the same JS file written, that may be very messy, resulting in maintenance is extremely inconvenient, then we can through the JS Modular development
1. If this is Jshelperone.js
//sandbox mode to prevent contamination of external variables; (function(window) {//define an object if the object already exists with the window, then we can use it directly varCloud = window. Cloud | | {}; //The attribute is defined on this object, and this property is an objectCloud.pagestringhelper ={stringcut:function(value,maxlength,sign) {if(Value.length <=maxLength)returnvalue; Else returnValue.substr (0, MaxLength) +Sign ; } }; //so that only cloud can be accessed externallyWindow. Cloud =Cloud;}) (window);
2. If B students want to expand this JS, then he can
;(function (window) { var Cloud = window. Cloud | | {}; = { function (value,sign) { return value.split (sign); } }; = Cloud;}) (window);
Make a call on the foreground page
<! DOCTYPE html> console.log (Cloud.PageStringHelper.StringCut (" ASDASDASD ", 5," ... ")); Console.log ("Cloud.PageStringSplitHelper.stringSplit", "," )); </script></body>
In this way, everyone is very familiar with their own piece of development, maintenance is also very convenient
JavaScript Modular Development Examples