编程语言/命名:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第15行: 第15行:
构造函数首字母应该{{underline|小|blue}}写<ref>Douglas Crockford. JavaScript: The Good Parts. O'Reily. 2008.</ref>。
构造函数首字母应该{{underline|小|blue}}写<ref>Douglas Crockford. JavaScript: The Good Parts. O'Reily. 2008.</ref>。
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
var nowDateLength = dateLength(nowDate); // dateLength is a ordinary function.</syntaxhighlight>
var nowDateStrLength = dateStrLength(nowDate); // dateStrLength is a ordinary function.</syntaxhighlight>


==== 构造函数命名 ====
==== 构造函数命名 ====

2020年6月12日 (五) 03:47的版本

引言

原则[1]:

  • 选择专业的词汇
  • 选择更具表现力的词汇
  • 避免模糊的词汇
  • 避免简洁的词汇
  • 附带更多信息在词尾
    eq: _ms 毫秒、_secs、_mb、_kbps

命名方法

匈牙利表示法

其他

函数命名

普通函数命名

构造函数首字母应该小写[2]。

var nowDateStrLength = dateStrLength(nowDate); // dateStrLength is a ordinary function.

构造函数命名

构造函数首字母应该大写。

var nowDate = new DateFormat(); // DateFormat is a constructor function.

实例

of还是for 示例 示例
示例 示例 示例
示例 示例 示例
  1. ↑ Dustin Boswell, Trevor Foucher. 编写可读代码的艺术(The Art of Readable Code)[M].尹哲, 郑秀雯. 北京:机械工业出版社,2012:12-16.
  2. ↑ Douglas Crockford. JavaScript: The Good Parts. O'Reily. 2008.