[英]How to document CoffeeScript source code with JSDoc?
我有一些用CoffeeScript編寫的代碼,我想用Google Closure Compiler優化生成的JavaScript,所以這些文件需要用JSDoc記錄。
我的問題是,如何記錄* .coffee文件以生成包含用於閉包編譯器的工作JSDoc的javascript?
還有一個問題:有沒有辦法在* .coffee中保留單行注釋?
### define function variable before block to avoid code being appended to closing part of JSDoc comment ###
cube = null
###*
* Function to calculate cube of input
* @param {number} Number to operate on
* @return {number} Cube of input
###
cube = (x) -> x*x*x
coffee -cpb src.coffee
// Generated by CoffeeScript 1.6.3
/* define function variable before block to avoid code being appended to closing part of JSDoc comment*/
var cube;
cube = null;
/**
* Function to calculate cube of input
* @param {number} Number to operate on
* @return {number} Cube of input
*/
cube = function(x) {
return x * x * x;
};
正如其他答案中詳述的那樣,CoffeeScript 1.7.1有更好的方法可以解決這個問題。
由於我不能直接回復上面的Billy,似乎CoffeeScript 1.7.1對此有更好的支持:
###*
# Sets the language and redraws the UI.
# @param {object} data Object with `language` property
# @param {string} data.language Language code
###
handleLanguageSet: (data) ->
輸出
/**
* Sets the language and redraws the UI.
* @param {object} data Object with `language` property
* @param {string} data.language Language code
*/
handleLanguageSet: function(data) {}
你必須進行實驗(很多),但###
評論是你的朋友。
咖啡腳本編譯器將保留使用###
表單的注釋( 此處為 docs)。
我嘗試使用網站上的'try coffeescript'功能為函數創建一個非常簡單的JsDoc
片段:
###* Doc for this function.###
foo = -> 'bar'
這給了:
/** Doc for this function.
*/
var foo;
foo = function() {
return 'bar';
};
我不是JsDoc
專家,但我猜的是var foo;
上面的函數聲明會產生問題。 如果你之前宣布過foo
,也許..
聽聽它是怎么回事真好。
class
有問題
###* this is a class ###
class hello
v: 4
給出了
// Generated by CoffeeScript 2.0.0-beta5
/** this is a class */
var hello;
hello = (function() {
class hello {};
hello.prototype.v = 4;
return hello;
})();
它在JSDoc中無效
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.