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__
JavaScript Patterns 2.10 Naming Conventions的更多相关文章
- JavaScript Patterns 4.10 Curry
Function Application apply() takes two parameters: the first one is an object to bind to this inside ...
- JavaScript Patterns 2.9 Coding Conventions
It’s important to establish and follow coding conventions—they make your code consistent, predictabl ...
- JavaScript Patterns 6.3 Klass
Commonalities • There’s a convention on how to name a method, which is to be considered the construc ...
- Naming Conventions for .NET / C# Projects
http://www.akadia.com/services/naming_conventions.html Naming Conventions for .NET / C# Projects Mar ...
- C# Coding & Naming Conventions
Reference document https://msdn.microsoft.com/en-us/library/ff926074.aspx https://msdn.microsoft.com ...
- 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 ...
- JavaScript Patterns 6.7 Borrowing Methods
Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...
- JavaScript Patterns 6.6 Mix-ins
Loop through arguments and copy every property of every object passed to the function. And the resul ...
- JavaScript Patterns 6.5 Inheritance by Copying Properties
Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...
随机推荐
- Repository模式中,Update总是失败及其解析
在Repository模式中,我的Update方法总是无法更新实体,这个非常郁闷,Update方法如下: 1: public virtual void Update(T entity) 2: { 3: ...
- jquery easyui dialog Bug解决方案
最近一直都在用easyui前端框架来开发设计UI,但在使用Dialog时,发现如果页面内容比较多,就会出现问题,首先看一下我的原代码: <input type="button" ...
- 下载image或者其他文件
public void SaveDownLoadAsPNG(Image img, string filePath) { try { WebRequest request = WebRequest.Cr ...
- HTML-DIV布局
<DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content= ...
- vs 2010 中类文文件模板的修改
类模板 文件的修改,以前也修改过,这次有个同事问我,搞了有一会才搞定,这里还是记录分享下. 如果想在每次创建文件时,自动生成文档注释(注意是自动生成文档注释而不是帮助文档),如下面的代码,需要设置VS ...
- (二)Protobuf的C#使用
[转]http://blog.csdn.net/shantsc/article/details/50729402 protobuf c#版本分成两个版本,一个是protobuf-net,另一个是pr ...
- Windows Azure开发者任务之五:配置虚拟机的“规模”
指定虚拟机的“规模”是怎么一回事? 我们可以指定角色将要部署于其上的虚拟机的“规模”.虚拟机的“规模”是指: 1,CPU核心数 2,内存容量 3,本地文件系统的体积 我们可以针对具体的角色来指定虚拟机 ...
- VB 2015 的 闭包(Closure)
是的,你没看错,这篇文章讲的不是 ECMAScript . 目前 VB 14 比 C# 6 领先的功能里面,有个即将在 C# 7 实现的功能,叫做"本地方法".这个功能与" ...
- 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议
[源码下载] 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议 作者:webabcd 介绍与众不同 windows ...
- Hibernate关联映射及高级查询
一.Hibernate中的关联关系 1.1.单向一对多关联关系 按照以下步骤配置hibernate中持久化类的一对多对象关联: (1).持久化类添加关联类的相关属性及getter/setter方法. ...