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__

JavaScript Patterns 2.10 Naming Conventions的更多相关文章

  1. JavaScript Patterns 4.10 Curry

    Function Application apply() takes two parameters: the first one is an object to bind to this inside ...

  2. JavaScript Patterns 2.9 Coding Conventions

    It’s important to establish and follow coding conventions—they make your code consistent, predictabl ...

  3. JavaScript Patterns 6.3 Klass

    Commonalities • There’s a convention on how to name a method, which is to be considered the construc ...

  4. Naming Conventions for .NET / C# Projects

    http://www.akadia.com/services/naming_conventions.html Naming Conventions for .NET / C# Projects Mar ...

  5. C# Coding & Naming Conventions

    Reference document https://msdn.microsoft.com/en-us/library/ff926074.aspx https://msdn.microsoft.com ...

  6. JavaScript Patterns 7.1 Singleton

    7.1 Singleton The idea of the singleton pattern is to have only one instance of a specific class. Th ...

  7. JavaScript Patterns 6.7 Borrowing Methods

    Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...

  8. JavaScript Patterns 6.6 Mix-ins

    Loop through arguments and copy every property of every object passed to the function. And the resul ...

  9. JavaScript Patterns 6.5 Inheritance by Copying Properties

    Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...

随机推荐

  1. 探索jdk8之ConcurrentHashMap 的实现机制

    在介绍ConcurrentHashMap源码之前,很有必要复习下java并发编程中的一些基础知识,比如内存模型等. 存储模型 并发编程中的三个概念 1.原子性 2.可见性 3.重排序 对HashMap ...

  2. 【Win10】【Win2D】实现控件阴影效果

    学过 WPF 的都知道,在 WPF 中,为控件添加一个阴影效果是相当容易的. <Border Width="100" Height="100" Backg ...

  3. Winform开发的界面处理优化

    在Winform开发中,客户体验是个很好的参考性指标,如果一个功能使用的时候感觉很流畅,说明我们的程序执行效率还不错,但是随着数据的真多,原先可能流程的地方可能会变得比较卡,这时候就需要追本索源,找到 ...

  4. windbg学习进阶之——windbg字段名及其意义

    要使用windbg分析dump必须加载正确的符号,可以通过设置Symbols File Path为"D:/Symbols;SRV*D:/Symbols*http://msdl.microso ...

  5. 外表cms,内在wiki的系统anwiki

    比较完整面向对象的语法格式,     外表cms,内在wiki的系统   http://enanocms.org/features   比较老,php4的语法

  6. json format validator

    http://la5u.org/archives/542 http://stedolan.github.io/jq/download/ https://linuxtoy.org/archives/jq ...

  7. 回文串---Palindrome

    POJ   3974 Description Andy the smart computer science student was attending an algorithms class whe ...

  8. 帝吧出征FB:这李毅吧的“爆吧”文化是如何形成的

    声明:本文不对爆吧行为及其涉及的事件进行是非判断,只探讨帝吧文化本身,欢迎拍砖.更正和补充. 一.“帝吧FB出征”事件梳理 继上次全网集体骂 “薯片”事件后,昨日(1月20日)晚7点,又发生了一次互联 ...

  9. mongodb 基本指令学习

    启动 : 1)创建一个文件夹存放mongodb的数据  启动的时候指定这个文件夹为存储mongodb的存储路径  我的目录是D:\data 2)启动mongodb服务  进入安装mongodb的bin ...

  10. A除以B问题

    描述:本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数.你需要输出商数Q和余数R,使得A = B * Q + R成立. 输入:输入在1行中依次给出A和B,中间以1空格分隔. 输出: ...