6

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

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。

4

1 回答 1

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
于 2016-03-13T13:28:54.400 回答