同义词
extends
语法
@augments <namepath>
概述
@augments
或 @extends
标记表示一个符号继承自父符号,并可能添加到父符号。你可以使用此标记来记录基于类的继承和基于原型的继承。
在 JSDoc 3.3.0 及更高版本中,如果一个符号继承自多个父符号,并且两个父符号具有名称相同的成员,则 JSDoc 使用 JSDoc 注释中列出的最后一个父符号的文档。
示例
在以下示例中,Duck
类被定义为 Animal
的子类。Duck
实例具有与 Animal
实例相同的属性,以及一个对 Duck
实例来说唯一的 speak
方法。
/**
* @constructor
*/
function Animal() {
/** Is this animal alive? */
this.alive = true;
}
/**
* @constructor
* @augments Animal
*/
function Duck() {}
Duck.prototype = new Animal();
/** What do ducks say? */
Duck.prototype.speak = function() {
if (this.alive) {
alert('Quack!');
}
};
var d = new Duck();
d.speak(); // Quack!
d.alive = false;
d.speak(); // (nothing)
在以下示例中,Duck
类继承自 Flyable
和 Bird
类,这两个类都定义了一个 takeOff
方法。由于 Duck
的文档将 @augments Bird
列在最后,因此 JSDoc 会自动使用 Bird#takeOff
中的注释来记录 Duck#takeOff
。
/**
* Abstract class for things that can fly.
* @class
*/
function Flyable() {
this.canFly = true;
}
/** Take off. */
Flyable.prototype.takeOff = function() {
// ...
};
/**
* Abstract class representing a bird.
* @class
*/
function Bird(canFly) {
this.canFly = canFly;
}
/** Spread your wings and fly, if possible. */
Bird.prototype.takeOff = function() {
if (this.canFly) {
this._spreadWings()
._run()
._flapWings();
}
};
/**
* Class representing a duck.
* @class
* @augments Flyable
* @augments Bird
*/
function Duck() {}
// Described in the docs as "Spread your wings and fly, if possible."
Duck.prototype.takeOff = function() {
// ...
};