gpt4 book ai didi

javascript - 如何使用 JSDoc 记录 CoffeeScript 源代码?

转载 作者:IT王子 更新时间:2023-10-29 03:04:56 24 4
gpt4 key购买 nike

我有一些用 CoffeeScript 编写的代码,我想用 Google Closure Compiler 优化生成的 JavaScript,所以这些文件需要用 JSDoc 记录。

我的问题是,我如何记录 *.coffee 文件以生成包含适用于闭包编译器的 JSDoc 的 javascript?

还有一个问题:有没有办法在 *.coffee 中保留单行注释?

最佳答案

CoffeeScript 输入:

### 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

Windows cmd 提示符的 JavaScript 输出: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;
};

编辑

详见 other answer CoffeeScript 1.7.1 有更好的方法来解决这个问题。

关于javascript - 如何使用 JSDoc 记录 CoffeeScript 源代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7833021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com