You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tags-augments.html
+59-15Lines changed: 59 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
<head>
6
6
<metacharset="utf-8">
7
-
<metaname="description" content="This object adds onto a parent object.">
7
+
<metaname="description" content="Indicate that a symbol inherits from, ands adds to, a parent symbol.">
8
8
<title>Use JSDoc: @augments</title>
9
9
<linkrel="stylesheet" href="styles/usejsdoc.css">
10
10
<linkrel="stylesheet" href="styles/prettify.css">
@@ -48,16 +48,16 @@ <h2 id="syntax">Syntax</h2>
48
48
<p><code>@augments <namepath></code>
49
49
</p>
50
50
<h2id="overview">Overview</h2>
51
-
<p>The @augments or@extends tag marks a symbol as augmenting another symbol.</p>
52
-
<p>While current versions of JavaScript don't allow classes or subclasses in the same way that class-based languages like Java do, many programmers choose to
53
-
think of their code structure in these terms. For this purpose JSDoc provides the @class and @extends tags. If you wish to express a similar relationship between
54
-
two symbols, but don't wish to promote the classical analogy, you can use the @constructor and @augments tags instead.</p>
51
+
<p>The <code>@augments</code> or<code>@extends</code> tag indicates that a symbol inherits from, and potentially adds to, a parent symbol. You can use this tag
52
+
to document both class-based and prototype-based inheritance.</p>
53
+
<p>In JSDoc 3.3.0 and later, if a symbol inherits from multiple parents, and both parents have identically named members, JSDoc uses the documentation from the
54
+
last parent that is listed in the JSDoc comment.</p>
55
55
<h2id="examples">Examples</h2>
56
-
<p>In the example below I wish to document the fact that Ducks are a specialised form of Animal: meaning that Duck instances are like Animal instances which have
57
-
been augmented with additional properties.
56
+
<p>In the following example, the <code>Duck</code> class is defined as a subclass of <code>Animal</code>. <code>Duck</code> instances have the same properties as
57
+
<code>Animal</code> instances, as well as a <code>speak</code> method that is unique to <code>Duck</code> instances.
58
58
</p>
59
59
<figure>
60
-
<figcaption>Documenting a class/subclass type of relationship.</figcaption><preclass="prettyprint lang-js"><code>/**
60
+
<figcaption>Documenting a class/subclass relationship</figcaption><preclass="prettyprint lang-js"><code>/**
<p>In the following example, the <code>Duck</code> class inherits from both the <code>Flyable</code> and <code>Bird</code> classes, both of which define a <code>takeOff</code> method. Because the documentation for <code>Duck</code> lists <code>@augments Bird</code> last, JSDoc automatically documents <code>Duck#takeOff</code> using
89
+
the comment from <code>Bird#takeOff</code>.</p>
90
+
<figure>
91
+
<figcaption>Multiple inheritance with duplicated method names</figcaption><preclass="prettyprint lang-js"><code>/**
92
+
* Abstract class for things that can fly.
93
+
* @class
94
+
*/
95
+
function Flyable() {
96
+
this.canFly = true;
97
+
}
98
+
99
+
/** Take off. */
100
+
Flyable.prototype.takeOff = function() {
101
+
// ...
102
+
};
103
+
104
+
/**
105
+
* Abstract class representing a bird.
106
+
* @class
107
+
*/
108
+
function Bird(canFly) {
109
+
this.canFly = canFly;
110
+
}
111
+
112
+
/** Spread your wings and fly, if possible. */
113
+
Bird.prototype.takeOff = function() {
114
+
if (this.canFly) {
115
+
this._spreadWings()
116
+
._run()
117
+
._flapWings();
118
+
}
119
+
};
120
+
121
+
/**
122
+
* Class representing a duck.
123
+
* @class
124
+
* @augments Flyable
125
+
* @augments Bird
126
+
*/
127
+
function Duck() {}
128
+
129
+
// Described in the docs as "Spread your wings and fly, if possible."
130
+
Duck.prototype.takeOff = function() {
131
+
// ...
132
+
};
87
133
</code></pre>
88
134
</figure>
89
-
<p>A related pattern can be documented with the @mixin and @mixes tags. Or, if the augmented symbol is only reusing one or two members of another symbol, you may
0 commit comments