【问题标题】:Visual studio web essentials JSDoc intellisense on methods assigned in constructor not working?Visual Studio Web Essentials JSDoc intellisense 在构造函数中分配的方法不起作用?
【发布时间】:2013-09-13 07:15:32
【问题描述】:

我对 jsdoc cmets 有点陌生(尝试将一些 vsdoc cmets 转换为 jsdoc,以便我可以使用支持 jsdoc 的文档生成器),所以如果我做的事情明显不正确,请阻止我,但我注意到如果您在构造函数的原型上分配方法,则智能感知适用于该成员:

/** 
 * @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; }

但是,如果您在构造函数中指定 bar,则 bar 方法上的智能感知会中断 - 它只会将整个注释、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; }; 
}

vsdoc intellisense 解析器能够处理原型上的方法或分配给 this 的方法,但是 jsdoc 解析器似乎被构造函数中分配给 this 的方法弄糊涂了。

【问题讨论】:

    标签: javascript visual-studio intellisense jsdoc web-essentials


    【解决方案1】:

    要处理这个问题,您需要在 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; }; 
    }
    

    JSDoc @memberofJSDOC @function。当您想要创建私有函数时,这也可以为您提供帮助(要记录私有函数,use the -p command when running JSDOC)。

    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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-09
      • 2014-01-05
      • 1970-01-01
      • 2014-04-18
      • 2016-03-08
      • 2020-03-02
      • 2017-02-01
      • 1970-01-01
      • 2023-03-06
      相关资源
      最近更新 更多