所以我有一个出口工厂功能的模块。工厂函数接受设置并返回绑定在该设置对象库。我不能为我的生活弄清楚如何与jsdocs记录这一点;我一直在玩的命名空间,类型定义,并memberof
直到我的头在旋转。无论我做什么,它只是没有列出的功能库定义的一部分。救命?
我可以让他们为全球功能表现,如果我完全去除的memberOf,但没有到目前为止,我已经试过让他们显示为成员函数
示例代码:
/**
* @namespace ServerControl
*/
/**
* @typedef {Object} Library
*/
/**
* Factory function that constructs a lib
* @param {*} settings Settings for constructing a lib
* @param {*} rancher The rancher library to be used by the lib
* @returns {ServerControl~Library} The lib
*/
module.exports = function(settings, rancher) {
return {
/**
* Evacuate a host
* @memberof {...ServerControl~Library}
* @method evacuate
* @param {String} name The name of the host to evacuate
* @returns {Promise} A promise that fulfills when the evacuation is done
*/
evacuate: name => {
const server = settings.servers.filter(item => item.display === name)[0];
return rancher.evacuateHost(server.host, server.env);
}
// [more methods snipped]
}
我有我的模块总是暴露工厂功能或功能的地图同样的问题。我总是用@typedef
模块封装之外。这样,我得到了IDEA的代码完成,可以产生很好的HTML文档。
Here the generated documentation这个例子:
/** @namespace SharedLib */
/**
* @typedef SharedLib.PriorityQueueFactory
* @function
* @template T
* @param {function(T, T): Boolean} comparator Comparison function like for <code>Array.prototype.sort</code>
* @return {{pop: function(Array<T>): Array<Array<T>| T>, push: function(Array<T>, T): Array<T>}} an object containing the functions to manage the queue
*/
// UMD wrapper - sorry!
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
}
else if (typeof module === 'object' && module.exports) {
module.exports = factory();
}
else {
root.returnExports = factory();
}
}(typeof self !== 'undefined' ? self : this,
function () {
/** @type {SharedLib.PriorityQueueFactory} */
function priorityQueueFactory(comparator) {
// ...
return priorityQueueFactory;
}));