相關:Correct way to document open-ended argument functions in JSDoc如何用已知參數類型文檔變量長度變量列表?
我說通過訪問arguments
可變接受多個陣列的函數:
/**
* @param options An object containing options
* @param [options.bind] blablabla (optional)
*/
function modify_function (options) {
for (var i=1; i<arguments.length; i++) {
// ...
}
}
現在,我知道,除了options
每個參數是包含值得文檔化值的數組:
[search_term, replacement, options]
我不考慮把(冗長的)描述放在變量參數行中。
@param {...}一個包含搜索項,替換項及其選項的數組;索引0:函數內的搜索項; 1:替換文字; 2:可選選項(catch_errors:捕獲錯誤並記錄它,在替換文本中escape:escape美元,pos:「L」用於在搜索項之前放置替換項,「R」用於放置它) 不可讀的解決方案,該類型不可見。
是否有方法來記錄變量參數的類型和值?
@param {...[]} An array with search terms, replacements and its options
@param {...[0]} The search term within the function
@param {...[1]} The replacement text
@param {...[2]} An optional object with obtions for the replacement
@param {...[2].catch_errors} catches errors and log it
@param {...[2].escape} etc...
以上相貌醜陋,但它應該給你什麼,我試圖實現一個想法:
- 文檔的變量參數(數組在這種情況下)類型
- 文檔此數組
- 文檔的對象的該數組
對於懶惰內的屬性,我已經採用的值d數組而不是對象。其他建議總是受歡迎的。
使用我認爲索引* 0,1, ... k *不是一個好方法。用字母或字母代替。 – sergzach
@sergzach:數組以數字索引,而不是字母。我想答案是我應該不那麼懶惰。 – Lekensteyn