@exports¶
-
.. @exports::
¶ - 语法
@exports <moduleName>
- 概述
在JSDoc 3.3.0及更高版本中, ``<moduleName>``可能包含``module: ``前缀. 在以前的版本中, 您必须省略此前缀.
在记录导出除“exports”对象或“module.exports”属性之外的任何内容的JavaScript模块时, 请使用@exports标记.
- 示例
在使用特殊“导出”对象的模块中, 永远不需要@exports标记. JSDoc自动识别正在导出此对象的成员. 类似地, JSDoc自动识别Node.js模块中的特殊“module.exports”属性.
CommonJS module¶/** * A module that says hello! * @module hello/world */ /** Say hello. */ exports.sayHello = function() { return 'Hello world'; };
Node.js module¶/** * A module that shouts hello! * @module hello/world */ /** SAY HELLO. */ module.exports = function() { return "HELLO WORLD"; };
AMD module that exports an object literal¶define(function() { /** * A module that whispers hello! * @module hello/world */ var exports = {}; /** say hello. */ exports.sayHello = function() { return 'hello world'; }; return exports; });
AMD module that exports a constructor¶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标记指示正在导出的内容.
AMD module that exports an object¶define(function () { /** * A module that says hello! * @exports hello/world */ var ns = {}; /** Say hello. */ ns.sayHello = function() { return 'Hello world'; }; return ns; });