JavaScript Modular Development Examples

Source: Internet
Author: User

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

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.