3

我正在使用Google Closure工具中的gjslint工具清理我的代码。据报告以下错误:为什么“会员不能有@私人JsDoc”?

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?谢谢!

+0

我会怀疑这是因为它只是“按照惯例私人”(例如,不是私人的封闭)。 – 2012-07-25 03:42:14

+0

有什么区别?我不认为任何注释是可执行的。 – 2012-07-25 03:55:04

+0

但它看起来像gslint正在尝试;-)也许这个“错误”可以降级为警告?或者'@ private'改变Closure Compiler输出/启发式? – 2012-07-25 04:13:52

回答

7

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

Used in conjunction with a trailing underscore on the method or property name to indicate that the member is private. Trailing underscores may eventually be deprecated as tools are updated to enforce @private .

作为闭幕短绒版本2.3.6,在误差“会员<名>不能有@private JsDoc”每当一个成员被标注@private没有将发射尾随下划线。

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

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

感谢您的解释! – 2012-07-25 04:30:44

+1

这不矛盾吗?!如果你确实输入'_',你就不会得到警告,但是如果你不这样做,那么它会告诉你应该添加它,尽管后来它可能会被弃用。 – 2014-04-07 23:44:48

相关问题