使用工厂即mylib.create()创建对象时要使用哪些JSDoc标签 [英] What JSDoc tags to use when creating objects with factory i.e. mylib.create()
问题描述
我的CommonJS模块使用工厂样式对象创建(.create()),我尝试拥有JSDoc样式文档,但无法弄清楚哪个 JSDoc 标记 @class
, @module
等。我应该用它做得很好。在下面,您可以看到该模块的简化结构。
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);
};
lib的使用方式如下。用户不知道,也不需要知道lib在 mylib.create()
后面的工作方式。
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'
因此,我的问题是,应如何标记函数以使其包含要包含的文档 mylib.create()
作为构造函数, mylib.instance.greet()
作为方法,不是包括有关仅在模块内部使用的 MyLib
对象的任何内容。
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.
推荐答案
我会说 @constructs
是您要寻找的内容(另请参见 http://usejsdoc.org/tags-constructs.html )。
I would say @constructs
is what you are looking for (see also http://usejsdoc.org/tags-constructs.html).
但是我认为应该将MyLib记录为一个类并创建为函数,该函数返回具有适当链接(例如 @see
)的该类的实例。
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
).
这篇关于使用工厂即mylib.create()创建对象时要使用哪些JSDoc标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!