简体   繁体   English

如何使用jsdoc记录函数发生器?

[英]How to document a function generator with jsdoc?

I am trying to document a function generator but without success, this is an example: 我试图记录函数生成器,但没有成功,这是一个例子:

function genericObjectGenerator(tagname) {
  var specificObject = function () {};

  specificObject.getClassName = function () {
    return tagname;
  }

  specificObject.prototype.sayHello = function(name) {
    return tagname + " says hello to " + name;
  }

  return specificObject;
}

var MyObject = genericObjectGenerator("object1");

var myObjectInstance = new MyObject();

myObjectInstance.sayHello();

How should i document the genericObjectGenerator and its specificObject functions in order to get JSDoc (and IntelliJ) to resolve the sayHello properly. 我应该如何记录genericObjectGenerator及其specificObject函数,以便让JSDoc(和IntelliJ)正确解析sayHello。

this should do the trick 这应该可以解决问题

/**
 * @param {string} tagname - the name of the tag
 * @returns {specificObject}
 */

function genericObjectGenerator(tagname) {
    var specificObject = function () {};

    specificObject.getClassName = function () {
        return tagname;
    };

    /**
     * @param {string} name - name as string
     * @returns {string}
     */

    specificObject.prototype.sayHello = function(name) {
        return tagname + ' says hello to ' + name;
    };

    return specificObject;
}

var MyObject = genericObjectGenerator('object1');

var myObjectInstance = new MyObject();

myObjectInstance.sayHello(123); // mark as warning
myObjectInstance.sayHello('123'); // not marking

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM