【问题标题】:Why is it that "Member must not have @private JsDoc"?为什么“会员不能有@private JsDoc”?
【发布时间】:2012-07-25 03:27:26
【问题描述】:

我正在使用 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 吗?谢谢!

【问题讨论】:

  • 我怀疑这是因为它只是“按惯例私有”(例如,不是私有关闭)。
  • 有什么区别?我不认为任何注释都是可执行的。
  • 但看起来 gslint 正在尝试 ;-) 也许那个“错误”可以降级为警告?还是@private 改变了闭包编译器的输出/启发式?

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


【解决方案1】:

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

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

从 Closure Linter 版本 2.3.6 开始,只要成员被注释为 @private 而没有尾随下划线,就会发出错误“成员 不能有 @private JsDoc”。

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

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

【讨论】:

  • 这不是矛盾吗?!如果您确实放了“_”,则不会收到警告,但如果您不放,它会告诉您应该添加它,即使以后它可能会被弃用...
猜你喜欢
  • 2012-11-04
  • 2015-01-13
  • 1970-01-01
  • 1970-01-01
  • 2016-03-30
  • 1970-01-01
  • 2017-03-05
  • 2017-12-23
  • 1970-01-01
相关资源
最近更新 更多