Visual Studio web essentials JSDoc intellisense在构造函数中分配的方法不起作用?

Jer*_*ell 5 javascript intellisense visual-studio jsdoc web-essentials

我对jsdoc注释有点新鲜(尝试将一些vsdoc注释转换为jsdoc,所以我可以使用支持jsdoc的doc生成器),所以如果我做的事情明显不正确,请阻止我,但是我注意到如果你分配了构造函数原型上的方法,intellisense适用于该成员:

/** 
 * @constructor 
 * @this {Foo} 
 */ 
function Foo() {}

/** 
 * A bar of Foo for you.
 * @param {string} baz A foo bar baz. 
 * @return {string} You get back what you give. 
 */ 
Foo.prototype.bar = function(baz) { return baz; }
Run Code Online (Sandbox Code Playgroud)

但是,如果在构造函数中指定bar,则bar方法上的intellisense会中断 - 它只显示整个注释,jsdoc标记和所有,作为单个块.它不显示参数类型或通过以下方式传递返回值:

/** 
 * @constructor 
 * @this {Foo} 
 * @param {string} baz A foo bar baz. 
 */ 
function Foo(baz) { 
  /** 
   * A bar of Foo and something else too.
   * @param {string} barzipan A little something extra. 
   * @return {string} You get back what you gave, and then some. 
   */ 
  this.bar = function(barzipan) { return baz + barzipan; }; 
}
Run Code Online (Sandbox Code Playgroud)

vsdoc intellisense解析器能够处理原型上的方法或分配给它的方法,但jsdoc解析器似乎被构造函数中分配给它的方法所混淆.

小智 2

为了解决这个问题,您需要向 jsdoc 值添加更多的语法糖。这是因为解析器不知道将“this.bar()”翻译为“Foo.bar()”。要解决该问题,请添加如下内容:

/** 
 * @constructor 
 * @this {Foo} 
 * @param {string} baz A foo bar baz. 
 */ 
function Foo(baz) { 
  /** 
   * A bar of Foo and something else too.
   * @param {string} barzipan A little something extra. 
   * @return {string} You get back what you gave, and then some. 
   * @function bar
   * @memberof {@link Foo}
   */ 
  this.bar = function(barzipan) { return baz + barzipan; }; 
}
Run Code Online (Sandbox Code Playgroud)

请参阅JSDoc @memberofJSDOC @function。当您想要创建私有函数时,这也可以为您提供帮助(要记录私有函数,请在运行 JSDOC 时使用 -p 命令)。

function Foo(baz) {
    /**
     * Returns what Bob did...
     * @param {string} doStuff Stuff to pass in.
     * @function bob
     * @memberof Foo
     * @private
     */
    var bob = function(doStuff) {
         return "Bob did " + doStuff;
    }
}
Run Code Online (Sandbox Code Playgroud)