为什么“会员不得拥有@private JsDoc”?

时间:2012-07-25 03:27:27

标签: javascript google-closure google-closure-library gjslint

我正在使用Google Closure Tools中的gjslint工具清理我的代码。它报告了以下错误:

Line 15, E:0222: Member "this._dictionary" must not have @private JsDoc

这是代码:

/**
 * Stacker class.
 * @constructor
 * @param {frankenstein.app.Dictionary} dictionary input dictionary for stacking.
 */
frankenstein.app.Stacker = function(dictionary) {
  /** @private */ this._dictionary = dictionary;
};

有人可以解释为什么this._dictionary必须没有@private JsDoc?谢谢!

1 个答案:

答案 0 :(得分:7)

Closure Linter旨在强制执行 Google JavaScript Style Guide 。 JSDoc标记@private记录如下:

  

与方法或属性名称上的 尾随下划线 结合使用,以指示该成员是私有的。随着工具的更新以强制执行@private,最终可能会弃用尾随下划线。

截至Closure Linter版本2.3.6,只要成员注释@private而没有尾随下划线,就会发出错误“Member< name>必须没有@private JsDoc”。

此代码不会发出任何错误或警告。

/**
 * Stacker class.
 * @constructor
 * @param {frankenstein.app.Dictionary} dictionary Input dictionary for 
 *     stacking.
 */
frankenstein.app.Stacker = function(dictionary) {
  /** @private */ this.dictionary_ = dictionary;
};