【问题标题】:JSDOC: Is it possible to link to a module property?JSDOC:是否可以链接到模块属性?
【发布时间】:2015-11-21 21:27:44
【问题描述】:
我想知道是否可以从一个模块链接到另一个模块的属性/方法。
到目前为止我已经尝试过但没有成功:
/**
* {@link module:modules/modulName#id}
*/
我的模块遵循这种模式:
/**
* @module modules/modulName
*/
define(function() {
'use strict';
/**
* @alias module:modules/modulName
*/
var module = {
/** Initialisation */
init: function() {}
};
return module;
});
有没有办法实现我想要的?
【问题讨论】:
标签:
requirejs
jsdoc
jsdoc3
【解决方案1】:
好吧,从我自己设法做的事情来看
/**
* @module namespace/moduleName
*/
/**
* @name module:namespace/moduleName#propName
* @type {Object}
*/
const propName= {}
然后在另一个文件中你可以参考:
/*
* @see module:namespace/moduleName#propName
*/
如果您有 @typedef 的名称,您可以使用 @link 甚至 @type。
用 PHPStorm 对此进行了测试,它可以正常工作。不知道使用 JSDOC 自动生成的 API。
【解决方案2】:
为此,我将要引用的属性声明为 @memberof 它自己的模块(是的,它与 @link 标记所在的模块相同)。
然后,我就这样做:{@link module:moduleName.property|textOfTheLink}
示例:
i18n.js 模块
/**
* @category Lib
* @subcategory i18n
* @module i18n
*/
/**
* Memoized translate method.
*
* @memberof module:i18n <----- THIS
* @type {MemoizedFunction}
* @function translate
* @param {i18n.Scope} scope - The translation scope.
* @param {i18n.TranslateOptions} [options] - Translate options.
* @version 1.0.0
* @since 1.0.0
* @example
* return <Text>{translate("home.title")}</Text>;
*/
export const translate = memoize(
(scope, options = undefined) => i18n.t(scope, options),
(scope, options = undefined) =>
options ? scope + JSON.stringify(options) : scope
);
/**
* Shorthand version of the {@link module:i18n.translate|translate} method. <----- COMBINED WITH THIS :)
*
* @function t
* @example
* const translatedError = t(`errors.codes.${errorCode}`, {
* defaults: [{ message: t("errors.codes.default") }],
* });
*/
export const t = translate;