我如何在CoffeeScript中发表评论?"/*this*/"不起作用

Eri*_* Hu 140 comments code-formatting commenting block-comments coffeescript

您可以用什么方式在CoffeeScript中发表评论?

文档说您可以使用三个哈希符号来启动和关闭注释块:

###
  Comments
  go
  here
###
Run Code Online (Sandbox Code Playgroud)

我发现我有时可以使用以下两种格式

`// backticks allow for straight-JavaScript,
 // but the closing backtick can't be on a comment line (I think?)
`
Run Code Online (Sandbox Code Playgroud)

有没有更简单的方法在CoffeeScript中插入简短的注释?

不要使用这种风格**

由于这得到了很多观点,我想强调一下

/* Comment goes here */
Run Code Online (Sandbox Code Playgroud)

/*它在自己的行上时产生MATH错误.

正如特雷弗在对这个问题的评论中指出的那样,这是一个正则表达式,而不是评论!

Mic*_*ant 262

使用单个#符号

# like this
Run Code Online (Sandbox Code Playgroud)

一个角色看起来很小;)

也:

###
This block comment (useful for ©-Copyright info) also gets 
passed on to the browsers HTML /* like this! */
###
Run Code Online (Sandbox Code Playgroud)

  • 啊*叹气*.官方文档通过他们的示例使用单个#形式,但从未在文本解释中实际提及它,它只讨论块注释. (5认同)
  • 这通常是您想要评论的方式; 当您希望评论落入javascript(通常是版权消息)时,最常使用三重哈希. (4认同)

mu *_*ort 24

评论的主要方式是sh/Perl/Ruby/...样式#评论:

# This comment goes to the end of the line
# and it won't appear in the "compiled"
# JavaScript version.
Run Code Online (Sandbox Code Playgroud)

如果希望评论显示在JavaScript版本中,请使用块样式###注释:

有时您想将块注释传递给生成的JavaScript.例如,当您需要在文件顶部嵌入许可标头时.阻止注释heredocs语法的块注释将保留在生成的代码中.

所以,如果你开始

###
PancakeParser is Public Domain
###
Run Code Online (Sandbox Code Playgroud)

然后你会在生成的JavaScript中得到这个JavaScript注释:

/*
PancakeParser is Public Domain
*/
Run Code Online (Sandbox Code Playgroud)