Front End Specification

Source: Internet
Author: User

Front-end Specification JavaScript specification

Reference 1-javascript-style-guide
Javascript-style-guide Original

Note
  1. [array] copy array using slice ()

        
       
    1. var len = items.length,
    2. itemsCopy = [],
    3. i;
    4. // bad
    5. for (i = 0; i < len; i++) {
    6. itemsCopy[i] = items[i];
    7. }
    8. // good
    9. itemscopy = items slice
  2. [array] use slice to convert an object of an array of classes to a group of

     
         
       
    1. function trigger () {
    2. var Span class= "PLN" > args = array Span class= "pun". prototype slice call arguments
    3. //...
    4. }
  3. [string] use single quotation marks for strings ‘‘ this personal habit, with a single quotation mark less click shift , too long string using stitching wrap

  4. string is used join instead of string connections to build strings, especially IE

        
       
    1. var items,
    2. messages,
    3. length, i;
    4. messages = [{
    5. state: ‘success‘,
    6. message: ‘This one worked.‘
    7. },{
    8. state: ‘success‘,
    9. message: ‘This one worked as well.‘
    10. },{
    11. state: ‘error‘,
    12. message: ‘This one did not work.‘
    13. }];
    14. length = messages.length;
    15. // bad
    16. function inbox(messages) {
    17. items = ‘<ul>‘;
    18. for (i = 0; i < length; i++) {
    19. items += ‘<li>‘ + messages[i].message + ‘</li>‘;
    20. }
    21. return items + ‘</ul>‘;
    22. }
    23. // good
    24. function inbox(messages) {
    25. items = [];
    26. for (i = 0; i < length; i++) {
    27. items[i] = messages[i].message;
    28. }
    29. return ‘<ul><li>‘ + items.join(‘</li><li>‘) + ‘</li></ul>‘;
    30. }
  5. [Properties] when accessing a property using a variable, use the brackets

  6. [variable]1) Always use var declaring variables to avoid polluting the global namespace; 2) var declare multiple variables with one and new lines, indent four spaces; 3)


From for notes (Wiz)

Front End Specification

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.