加载中...

@exports


描述: 标识一个由JavaScript模块导出的成员。

Syntax(语法)

@exports <moduleName>

在JSDoc3.3.0或更高版本中,<moduleName>可以包含module: 前缀。在以前的版本中,你必须忽略此前缀。

Overview(概述)

@exports标签描述由JavaScript模块的exportsmodule.exports属性导出的任何内容。

Examples(例子)

在模块中,当您使用特定的exports模块,@exports标签是不需要。JSDoc会自动识别出该对象的导出成员。同样,JSDoc会自动识别中的Node.js模块特定的module.exports属性。

例如,CommonJS模块:

  1. /**
  2. * A module that says hello!
  3. * @module hello/world
  4. */
  5. /** Say hello. */
  6. exports.sayHello = function() {
  7. return 'Hello world';
  8. };

例如,Node.js模块:

  1. /**
  2. * A module that shouts hello!
  3. * @module hello/world
  4. */
  5. /** SAY HELLO. */
  6. module.exports = function() {
  7. return "HELLO WORLD";
  8. };

例如,AMD模块导出一个字面量对象:

  1. define(function() {
  2. /**
  3. * A module that whispers hello!
  4. * @module hello/world
  5. */
  6. var exports = {};
  7. /** say hello. */
  8. exports.sayHello = function() {
  9. return 'hello world';
  10. };
  11. return exports;
  12. });

例如,AMD模块导出一个构造函数:

  1. define(function() {
  2. /**
  3. * A module that creates greeters.
  4. * @module greeter
  5. */
  6. /**
  7. * @constructor
  8. * @param {string} subject - The subject to greet.
  9. */
  10. var exports = function(subject) {
  11. this.subject = subject || 'world';
  12. };
  13. /** Say hello to the subject. */
  14. exports.prototype.sayHello = function() {
  15. return 'Hello ' + this.subject;
  16. };
  17. return exports;
  18. });

如果你的模块导出使用的是exportsmodule.exports之外的其他方法,使用@exports标签来说明哪些成员用于导出。

例如:AMD模块导出一个对象:

  1. define(function () {
  2. /**
  3. * A module that says hello!
  4. * @exports hello/world
  5. */
  6. var ns = {};
  7. /** Say hello. */
  8. ns.sayHello = function() {
  9. return 'Hello world';
  10. };
  11. return ns;
  12. });

还没有评论.