zoukankan      html  css  js  c++  java
  • JavaScript Patterns 2.10 Naming Conventions

    1. Capitalizing Constructors

    var adam = new Person();

    2. Separating Words

    camel case - type the words in lowercase, only capitalizing the first letter in each word.

    upper camel case, as in  MyConstructor(),

    lower  camel  case,  as  in  myFunction(), calculateArea()and getFirstName()

    variable names - first_name,  favorite_bands,  and old_company_name.

    ECMAScript uses camel case for both methods and properties, although the multiword property  names are rare (lastIndex and  ignoreCase properties of regular expression objects).

    3. Other Naming Patterns

    Constants - Number.MAX_VALUE

    // precious constants, please don't touch

    var PI = 3.14,

    MAX_WIDTH = 800;

    Naming globals with all caps can reinforce the practice of minimizing their number and can make them easily distinguishable.

    use an underscore prefix to denote a private method or property.

    var person = {
    
        getName: function () {
            return this._getFirst() + ' ' + this._getLast();
        },
    
        _getFirst: function () {
            // ...
        },
    
        _getLast: function () {
            // ...
        }
    }; 

    Note that JSLint will complain about the underscore prefixes, unless you set the option nomen: false.

    Following are some varieties to the _private convention:

    • Using a trailing underscore to mean private, as in name_ and getElements_()

    • Using  one  underscore  prefix  for  _protected properties  and  two  for  __private properties

    • In Firefox some internal properties not technically part of the language are available, and they are named with a two underscores prefix and a two underscore suffix, such as __proto__ and __parent__ 

  • 相关阅读:
    .net core 3.0中可以使用gRPC了
    Java clone() 浅克隆与深度克隆(转)
    CENTOS下搭建SVN服务器(转)
    设置eclipse不同的workspace共享配置
    在Eclipse添加Android兼容包( v4、v7 appcompat )(转)
    【原创】Nginx+PHP-FPM优化技巧总结(转)
    【汇总】PHP-FPM 配置优化(转)
    nginx File not found 错误(转)
    nginx php-fpm安装配置(转)
    nginx优化(转)
  • 原文地址:https://www.cnblogs.com/haokaibo/p/Naming-Conventions.html
Copyright © 2011-2022 走看看