【学习笔记】JavaScript编码规范- 注释

多行注释使用/**……*/,需要包含一个描述,所有参数的具体类型的值还有返回值。

// bad
// make() returns a new element
// based on the passed in tag name
//
// @param {String} tag
// @return {Element} element
function make(tag) {


// ...stuff...


return element;
}


// good
/**
* make() returns a new element
* based on the passed in tag name
*
* @param {String} tag
* @return {Element} element
*/
function make(tag) {


// ...stuff...


return element;
}

单行注释使用//,把单行注释放在语句的上一行,并且在注释之前空一行。

// bad
var active = true; // is current tab


// good
// is current tab
var active = true;


// bad
function getType() {
console.log('fetching type...');
// set the default type to 'no type'
var type = this._type || 'no type';


return type;
}


// good. God Bless!
function getType() {
console.log('fetching type...');


// set the default type to 'no type'
var type = this._type || 'no type';


return type;
}

如果你指出的问题需要重新定位或者提出一个待解决的问题需要实现,给注释添加FIXME or TODO 前缀有利于其他开发者快速理解。这些注释不同于通常的注释,因为它们是可实施的。这些实施措施就是FIXME -- need to figure this out or TODO -- need to implement.

function AAA() {


// <strong>使用// FIXME:给一个问题作注释 </strong>FIXME: shouldn't use a global here
total = 0;


return this;
}

function BBB() {


// <strong>使用//TODO:给问题解决方案作注释 </strong>TODO: total should be configurable by an options param
this.total = 0;


return this;
}


1:11 And God said,Let the earth bring forth grass,the herb yielding seed,and thr fruit tree yielding fruit after his kind,whose seed is in itself,upon the earth;and it was so.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值