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

时间:2012-08-15 18:46:32

标签: javascript jsdoc

我正在尝试记录函数生成器,但没有成功,这是一个例子:

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();

我应该如何记录genericObjectGenerator及其specificObject函数,以便让JSDoc(和IntelliJ)正确解析sayHello。

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题

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