7
为了避免在我的JavaScript代码中使用new
,我编写了工厂来创建对象。用JSDoc记录工厂
我已经尝试了多种组合,并且给了我最满意的结果之一是:
/**
* Document module
* @module app/document
*/
(function() {
'use strict';
/**
* Factory that creates a document object.
* @alias module:app/document.factory
* @return {document}
*/
function document() {
/**
* Get document id
* @method id
* @return {String}
*/
var id = function id() {...},
api = {
id: id
};
return api;
}
/**
* This module exports the {@link module:app/document.factory|factory} function.
*/
module.exports = document;
}());
的问题,这些意见是没有定义document
对象。因此,我不能在另一个对象中引用此对象,并且在扩展此对象时我无法继承它的文档。
什么是适当的方式来记录这种类型的对象?
如果我使用@typedef
标签,我得到的静态factory
方法 和document
对象正确记录 而是由JSDoc不会产生id
方法的文档:
/**
* Document module.
* @module app/document
*/
(function() {
'use strict';
/**
* Factory that creates a document object.
* @function module:app/document.factory
* @return {document}
*/
function factory(agent) {
/**
* @callback document~id
* @returns {String}
*/
var id = function id() {...},
/**
* @typedef document
* @property {document~id} id
*/
document = {
id: id
};
return document;
}
module.exports = factory;
}());
尽量不要哟使用保留的关键字作为文档或功能的ID – Sagi
使用@typedef - 这将允许您引用它 –
@ elad.chen我编辑了问题以尝试与@ @ typedef',但我没有得到预期的结果。 – goriol