【學習筆記】JavaScript編碼規範- 注釋

來源:互聯網
上載者:User

標籤:javascript

多行注釋使用/**……*/,需要包含一個描述,所有參數的具體類型的值還有返回值。

// bad// make() returns a new element// based on the passed in tag name//// @param {String} tag// @return {Element} elementfunction 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;}

單行注釋使用//,把單行注釋放在語句的上一行,並且在注釋之前空一行。

// badvar active = true; // is current tab// good// is current tabvar active = true;// badfunction 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 heretotal = 0;return this;}

function BBB() {// <strong>使用//TODO:給問題解決方案作注釋 </strong>TODO: total should be configurable by an options paramthis.total = 0;return this;}


God bless You!


【學習筆記】JavaScript編碼規範- 注釋

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.