How to document a function generator using jsdoc?

I am trying to document a function generator, but to no avail, 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 genericObjectGenerator and its specificObject functions to force JSDoc (and IntelliJ) to correctly say sayHello.

+6
source share
1 answer

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 
0
source

Source: https://habr.com/ru/post/922975/


All Articles