语法
@exports <moduleName>
在 JSDoc 3.3.0 及更高版本中,<moduleName>
可以包含 module:
前缀。在之前的版本中,您必须省略此前缀。
概述
在记录导出除“exports”对象或“module.exports”属性之外任何内容的 JavaScript 模块时,请使用 @exports 标记。
示例
在您使用特殊“exports”对象的模块中,永远不需要 @exports 标记。JSDoc 会自动识别此对象的成员正在导出。类似地,JSDoc 会自动识别 Node.js 模块中的特殊“module.exports”属性。
/**
* A module that says hello!
* @module hello/world
*/
/** Say hello. */
exports.sayHello = function() {
return 'Hello world';
};
/**
* A module that shouts hello!
* @module hello/world
*/
/** SAY HELLO. */
module.exports = function() {
return "HELLO WORLD";
};
define(function() {
/**
* A module that whispers hello!
* @module hello/world
*/
var exports = {};
/** say hello. */
exports.sayHello = function() {
return 'hello world';
};
return exports;
});
define(function() {
/**
* A module that creates greeters.
* @module greeter
*/
/**
* @constructor
* @param {string} subject - The subject to greet.
*/
var exports = function(subject) {
this.subject = subject || 'world';
};
/** Say hello to the subject. */
exports.prototype.sayHello = function() {
return 'Hello ' + this.subject;
};
return exports;
});
如果您的模块导出的对象名称不是“exports”或“module.exports”,请使用 @exports 标记来指示正在导出什么。
define(function () {
/**
* A module that says hello!
* @exports hello/world
*/
var ns = {};
/** Say hello. */
ns.sayHello = function() {
return 'Hello world';
};
return ns;
});