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. Android学习笔记(第二篇)View中的五大布局

    PS:人不要低估自己的实力,但是也不能高估自己的能力.凡事谦为本... 学习内容: 1.用户界面View中的五大布局... i.首先介绍一下view的概念   view是什么呢?我们已经知道一个Act ...

  2. IOS开发UI基础之Plis文件-字典转模型

    什么是plist文件? 在开发中直接将数据写在代码里面 不是一种合理的做法 如果数据经常改变 就需要经常翻开对应的代码进行修改 造成代码扩展性低 因此,可以考虑将经常变的数据放在⽂文件中进⾏行存储,程 ...

  3. BAT及各大互联网公司前端笔试面试题--Html,Css篇

    注意 转载须保留原文链接(http://www.cnblogs.com/wzhiq896/p/5931347.html )作者:wangwen896 整理分享出来希望更多的前端er共同进步吧,不仅适用 ...

  4. Linq专题之查询操作

    前面我们主要讲解的是Linq的查询表达式,Linq不但提供了一些基本的查询表达式,还提供了数十个查询操作.比如筛选操作.聚合操作.投影操作等等.通过这些查询操作可以更方便的对数据源进行处理. Linq ...

  5. 那晚征服的一道js经典的面试题

    今天朋友共享了一道js中经典的面试题,需求是这样的 给定你任意一个字符串,让你写出一个算法,求算出该字符串中出现次数最多的一个字符,并将其结果输出 刚拿到这道题的第一感觉便是定义一个count计时器, ...

  6. Java开发中的23种设计模式(转)

    设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...

  7. ActiveReports 9 新功能:可视化查询设计器(VQD)介绍

    在最新发布的ActiveReports 9报表控件中添加了多项新功能,以帮助你在更短的时间里创建外观绚丽.功能强大的报表系统,本文将重点介绍可视化数据查询设计器,无需手动编写任何SQL语句,主要内容如 ...

  8. QQ视差特效和ListView侧滑删除

    如图所示是效果图,当向下拉时,图片会被拉出来,松手后恢复.和ListView的侧滑删除   1.视差特效 首先图片是通过addHeaderView加上去的,所以在设置Adapter前先设置一个View ...

  9. Scala Collection简介

    Traversable vs Iterable Traversable, Iterable 都是trait. Iterable 继承 Traversable. Traversable: 支持forea ...

  10. Hibernate中的一级缓存、二级缓存和懒加载(转)

    1.为什么使用缓存 hibernate使用缓存减少对数据库的访问次数,从而提升hibernate的执行效率.hibernate中有两种类型的缓存:一级缓存和二级缓存. 2.一级缓存 Hibenate中 ...