Source Code Fundamentals: Comments

Hack 的注释有三种写法:

// A single line comment.

# Also a single line comment.

/* A multi line comment.
 *
 */

/**
 * A doc comment starts with two asterisks.
 *
 * It summarises the purpose of a definition, such as a
 * function, class or method.
 */
function foo(): void {}

多行注释以 /* 开始、*/ 结束。以 /** 开头的通常用于文档。

单行注释以 // 或者 # 开始,下一行结束。

还有一些可以被程序识别的特殊注释:

  • // FALLTHROUGH 用于 switch 语句
  • // strict// partial 用于 起始标记
  • /* HH_FIXME[1234] */ 或者 /* HH_IGNORE_ERROR[1234] */ 可以抑制类型检查器报告 1234 错误。

本节由 Y!an 翻译