What JSDoc tags to use when creating objects with factory i.e. mylib.create()

匆匆过客 提交于 2019-12-25 03:43:13

问题


My CommonJS module uses a factory style object creation (.create()) and I try to have JSDoc style documentation but cannot figure out which JSDoc tags @class, @module etc. I should to use to do it nicely. Below you can see a simplified structure of the module.

var MyLib = function () {
  this.msg = 'Hello';
};

exports.create = function () {
  return new MyLib();
};

MyLib.prototype.greet = function () {
  console.log(this.msg);
};

The lib is used in the following way. User does not know and does not need to know anything about how the lib works behind mylib.create().

var mylib = require('mylib');
var a = mylib.create();
a.greet(); // 'Hello'

Therefore my question is, how should I tag the functions to have documentation to include mylib.create() as a constructor, mylib.instance.greet() as a method and not include anything about MyLib object that is used only inside the module.


回答1:


I would say @constructs is what you are looking for (see also http://usejsdoc.org/tags-constructs.html).

But I would argue that should document MyLib as a class and create as a function which returns an instance of that class with a proper link (i.e. @see).



来源:https://stackoverflow.com/questions/28947649/what-jsdoc-tags-to-use-when-creating-objects-with-factory-i-e-mylib-create

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!