2012-06-27 24 views
0

你們如何寫一些簡單的代碼,你只用於自己的意見?您的方式來寫簡單的評論

我主要是寫JavaScript和PHP代碼,我真的覺得我找不到寫評論的好方法。

如果我有簡短的代碼行,我經常這樣做:

x = doThis(getSomeValueFromSomewhere()); // This is a short line of code 

這似乎真的很好,我認爲,但是當行獲得多條線路長一點或者它並不真正起作用,

// Dont really like this since it's not clear if it describes only line 1, or all lines. 
aLongerVariableName = (getSomeValueFromSomewhere() == "this is what I want") ? "true value" : "false value"; 
x = doThis(aLongerVariableName); 

那麼,你是怎麼做到的?

回答

0
(* 
* For blocks of comments that serve as important documentation 
* e.g descriptions of functions. 
*) 

像你一樣,也許重新格式化爲

(* For blocks of comments thet serve as important documentation 
    * e.g descriptions of functions. *) 

而對於短期內聯評論//。 不要忘了Ctrl- /是你的朋友;-)

0

一個簡單的方法來改善JavaScript中的評論/分解塊,這在編程時非常簡單和快速。

當你想在JavaScript中,你需要添加這個衆所周知的方式註釋塊:

/* 
... 
*/ 

所以,當你需要decomment您需要更改開始/ *和* /結束,但我用這樣的:

/* 
... 
//*/ 

這種方式改變的開始/ *到// *您將decomment整個區塊,僅addning一個字符,而不需要搜索註釋的結尾。