【问题标题】:jsDoc @constructs not inherited by extending Objects?jsDoc @constructs 不是通过扩展对象继承的?
【发布时间】:2017-04-24 00:19:35
【问题描述】:

我使用 @lends + @constructs + @augments 进行 MooTools 类定义(自定义命名空间变体),但是如果我在扩展类中不包含初始化,我会在 PhpStorm 中遇到一些扩展类的检查问题上面有一个@constructs。 jsDoc 中是否不可能在扩展类中省略初始化,或者 PhpStorm 检查无法正常工作?

new Class('Validator.Generic',
/**
 * @lends Validator.Generic
 */
{
    /**
     * @constructs
     */
     initialize:function(){}
}

new Class('Validator.Regex',
/**
 * @augments Validator.Generic
 * @lends Validator.Regex
 */
{
    //PhpStorm inspection reports unrecognized symbol Regex unless
    //I add a method with @constructs here, even though the class
    //it augments has a constructor
});

我也尝试过变体。仅当我将初始化添加到扩展类(例如 Validator.Regex)以及 @constructs 标记到文档块时,它才有效。这当然不理想。

【问题讨论】:

  • add /** @class Validator.Regex */ above new Class('Validator.Regex') - 这应该会有所帮助
  • @lena 将此作为答案,以便我给予您信任。这似乎是我所追求的。

标签: mootools phpstorm jsdoc


【解决方案1】:

尝试在new Class('Validator.Regex')上方添加/** @class Validator.Regex */

【讨论】:

  • 查看我添加的答案了解详情
【解决方案2】:

@lena 的回答部分有效,但在看似相同的情况下仍然任意未通过检查。我改变了方法,考虑了标签名称的字面含义。结论:“@class”是定义一个类型(伪静态),“@augments”和“@lends”在基于原型的语言的上下文中应该暗示实例扩展。这是事后的直觉。现在所有检查都使用以下语法通过。

/** * @class Validator.Regex * @augments {Validator.Generic} */ new Class('Validator.Regex', /** * @lends {Validator.Regex} */ {} );

【讨论】:

  • 太糟糕了,这个语法必须如此冗长,但 PhpStorm 正则表达式替换路径再次对加快进程有很大帮​​助。
猜你喜欢
  • 2015-02-27
  • 2010-11-07
  • 2017-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-03
相关资源
最近更新 更多