【问题标题】:JSDocs - How to document implicit parameters and returnsJSDocs - 如何记录隐式参数和返回
【发布时间】:2016-12-15 07:43:54
【问题描述】:

我想知道如何记录如下函数:

var createInput = function () {
  var type = this.type;

  this.input = {
    val: {},
    type: type
  };
}

从技术上讲,this.type 是一个输入参数,而 this.input 是从该对象返回的内容。如何记录这一点?

【问题讨论】:

    标签: javascript documentation jsdoc


    【解决方案1】:

    sapithpocker 在第二个链接上的翻唱似乎显示了一个潜在的解决方案。

    /**
     * The context of the current class.
     * @typedef {Object} ClassContext.
     * @property {string} type - Indicates type. */
    
    /**
     * A method for doing something.
     * @param {...ClassContext} this - a {@link ClassContext} object.
     */
    function createInput() { /* Code */ }
    

    这是可以为每个方法重用的文档,使用对象“拥有”当前上下文,即this,并且也遵循 DRY 原则。

    【讨论】:

      【解决方案2】:

      最好以某种方式重写代码,以便它接受参数并返回一些值而没有任何副作用。也很容易记录!

      问题应该更像是如何避免副作用,而不是如何记录副作用

      var createInput = function (type) {
        return {
          val: {},
          type: type
        };
      }
      
      this.input = createInput(this.type);
      

      【讨论】:

      • 原则上我同意,但我们在代码中使用了很多具有隐式共享变量的层次结构。我基本上需要在每个函数中发送context 作为参数,即使我可以通过this 直接访问它。我认为问题可以写成:如何在 JSDocs 中记录类变量?
      • 你的意思是object作为参数?
      • 检查thisthis
      猜你喜欢
      • 1970-01-01
      • 2015-10-27
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      • 2020-02-28
      相关资源
      最近更新 更多