JavaScript Development Experience Finishing

Source: Internet
Author: User

This year contacted a B/S project, summed up some JavaScript development experience, organize some useful content to share with you. This article will continue to update ...

1 . Implement code access control

  As the project JavaScript code base expands, the functions and variables that should be controlled in the private scope will leak more and more, and your global scope will become more and more likely to be contaminated. This not only causes naming conflicts, but also provides a hotbed for bugs. Therefore, we need to write a self-contained, opaque JavaScript code that does not leak internal details to the outside world and does not conflict with existing frameworks and script libraries. In fact, this is the main requirement for large-scale programming

Examples are as follows:

//to define an obj object    varobj = (function () {        varPrivatefield = 42; varPublicfield = ' Foobar '; //obj Object Private Method        functionprocessinternals () {alert (' Private: ' +Privatefield); }        //obj Object Private Method        functionrun () {processinternals (); Alert (' Private: ' +Privatefield); Alert (' Public: ' +Publicfield); }              return{Publicfield:publicfield,//returns the name of the Publicfield private variableRun:run//returns the name of the run private method        }; })();//Note the increase () here;Obj.run ();//call the Obj object Run () methodObj.publicfield;//Call obj Object Public Propertyobj.processinternals ();//Access Private method, nullObj.privatefield;//Access private property, null

2. use optional/variable/named parameters

JavaScript Development Experience Finishing

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.