加载中...

@augments


指名这个子类继承至哪个父类,后面需要加父类名

别名:@extends

Syntax(语法)

@augments <namepath>

Overview(概述)

@augments or@extends标签指明标识符继承自哪个父类,后面需要加父类名。你可以使用这个标签来记录基于类和并基于原型的继承。

在JSDoc3.3.0或更高版本中,如果一个标识符继承自多个父类,并且多个父类有同名的成员,JSDoc使用来自列出的JSDoc注释中最后一个父类的文档。

Examples (例子)

在下面的例子中,Duck 类被定义为Animal的子类。Duck实例和Animal实例具有相同的属性,以及 speak方法是Duck实例所独有的。

例如,描述一个父类和子类的关系:

  1. /**
  2. * @constructor
  3. */
  4. function Animal() {
  5. /** Is this animal alive? */
  6. this.alive = true;
  7. }
  8. /**
  9. * @constructor
  10. * @augments Animal
  11. */
  12. function Duck() {}
  13. Duck.prototype = new Animal();
  14. /** What do ducks say? */
  15. Duck.prototype.speak = function() {
  16. if (this.alive) {
  17. alert('Quack!');
  18. }
  19. };
  20. var d = new Duck();
  21. d.speak(); // Quack!
  22. d.alive = false;
  23. d.speak(); // (nothing)

在下面的例子中,Duck 类继承自FlyableBird 类,这两个父类都定义了一个takeOff方法。由于@augments Bird 是在 Duck 文档列表中最后,JSDoc自动使用Bird#takeOff注释来记录Duck#takeOff

例如,用重写方法来实现多重继承:

  1. /**
  2. * Abstract class for things that can fly.
  3. * @class
  4. */
  5. function Flyable() {
  6. this.canFly = true;
  7. }
  8. /** Take off. */
  9. Flyable.prototype.takeOff = function() {
  10. // ...
  11. };
  12. /**
  13. * Abstract class representing a bird.
  14. * @class
  15. */
  16. function Bird(canFly) {
  17. this.canFly = canFly;
  18. }
  19. /** Spread your wings and fly, if possible. */
  20. Bird.prototype.takeOff = function() {
  21. if (this.canFly) {
  22. this._spreadWings()
  23. ._run()
  24. ._flapWings();
  25. }
  26. };
  27. /**
  28. * Class representing a duck.
  29. * @class
  30. * @augments Flyable
  31. * @augments Bird
  32. */
  33. function Duck() {}
  34. // Described in the docs as "Spread your wings and fly, if possible."
  35. Duck.prototype.takeOff = function() {
  36. // ...
  37. };

还没有评论.