8000 make the `@lends` example actually generate docs (jsdoc3/jsdoc#1305) · ethereum-node/jsdoc.github.io@1c98869 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c98869

Browse files
committed
make the @lends example actually generate docs (jsdoc/jsdoc#1305)
1 parent 5d44e12 commit 1c98869

File tree

2 files changed

+78
-25
lines changed

2 files changed

+78
-25
lines changed

content/en/tags-lends.md

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ a function that creates a named class from its members.
2020

2121
## Examples
2222

23-
In this example, we want to use a helper function to make a class named "Person," along with
24-
instance methods named "initialize" and "say." This is similar to how some popular frameworks
23+
In this example, we want to use a helper function to make a class named `Person`, along with
24+
instance methods named `initialize` and `say`. This is similar to how some popular frameworks
2525
handle class creation.
2626

2727
{% example "Example class" %}
@@ -42,10 +42,10 @@ var Person = makeClass(
4242
```
4343
{% endexample %}
4444

45-
Without any comments, JSDoc won't recognize that this code creates a "Person" class with two
46-
methods. To document the methods, we must use a "@lends" tag in a doc comment immediately before the
47-
object literal. The @lends tag tells JSDoc that all the member names of that object literal are
48-
being "lent" to a variable named "Person."
45+
Without any comments, JSDoc won't recognize that this code creates a `Person` class with two
46+
methods. To document the methods, we must use a `@lends` tag in a doc comment immediately before the
47+
object literal. The `@lends` tag tells JSDoc that all the member names of that object literal are
48+
being "loaned" to a variable named `Person`. We must also add comments to each of the methods.
4949

5050
The following example gets us closer to what we want:
5151

@@ -56,9 +56,18 @@ The following example gets us closer to what we want:
5656
var Person = makeClass(
5757
/** @lends Person */
5858
{
59+
/**
60+
* Create a `Person` instance.
61+
* @param {string} name - The person's name.
62+
*/
5963
initialize: function(name) {
6064
this.name = name;
6165
},
66+
/**
67+
* Say something.
68+
* @param {string} message - The message to say.
69+
* @returns {string} The complete message.
70+
*/
6271
say: function(message) {
6372
return this.name + " says: " + message;
6473
}
@@ -67,9 +76,9 @@ var Person = makeClass(
6776
```
6877
{% endexample %}
6978

70-
Now the functions named "initialize" and "say" will be documented, but they appear as static methods
71-
of the "Person" class. That is possibly what you meant, but in this case we want "initialize" and
72-
"say" to belong to the instances of the "Person" class. So we change things slightly by lending the
79+
Now the functions named `initialize` and `say` will be documented, but they appear as static methods
80+
of the `Person` class. That is possibly what you meant, but in this case we want `initialize` and
81+
`say` to belong to the instances of the `Person` class. So we change things slightly by lending the
7382
methods to the class's prototype:
7483

7584
{% example "Documented as instance methods" %}
@@ -79,9 +88,18 @@ methods to the class's prototype:
7988
var Person = makeClass(
8089
/** @lends Person.prototype */
8190
{
91+
/**
92+
* Create a `Person` instance.
93+
* @param {string} name - The person's name.
94+
*/
8295
initialize: function(name) {
8396
this.name = name;
8497
},
98+
/**
99+
* Say something.
100+
* @param {string} message - The message to say.
101+
* @returns {string} The complete message.
102+
*/
85103
say: function(message) {
86104
return this.name + " says: " + message;
87105
}
@@ -90,21 +108,30 @@ var Person = makeClass(
90108
```
91109
{% endexample %}
92110

93-
One final step: Our class framework uses the loaned "initialize" function to construct Person
94-
instances, but a Person instance does not have its own "initialize" method. The solution is to add
95-
the @constructs tag to the loaned function. Remember to remove the @class tag as well, or else two
96-
classes will be documented.
111+
One final step: Our class framework uses the loaned `initialize` function to construct `Person`
112+
instances, but a `Person` instance does not have its own `initialize` method. The solution is to add
113+
the `@constructs` tag to the loaned function. Remember to remove the `@class` tag as well, or else
114+
two classes will be documented.
97115

98116
{% example "Documented with a constructor" %}
99117

100118
```js
101119
var Person = makeClass(
102120
/** @lends Person.prototype */
103121
{
104-
/** @constructs */
122+
/**
123+
* Create a `Person` instance.
124+
* @constructs
125+
* @param {string} name - The person's name.
126+
*/
105127
initialize: function(name) {
106128
this.name = name;
107129
},
130+
/**
131+
* Say something.
132+
* @param {string} message - The message to say.
133+
* @returns {string} The complete message.
134+
*/
108135
say: function(message) {
109136
return this.name + " says: " + message;
110137
}

tags-lends.html

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ <h2 id="overview">Overview</h2>
4444
<p>The <code>@lends</code> tag allows you to document all the members of an object literal as if they were members of a symbol with the given name. You might want
4545
to do this if you are passing an object literal into a function that creates a named class from its members.</p>
4646
<h2 id="examples">Examples</h2>
47-
<p>In this example, we want to use a helper function to make a class named &quot;Person,&quot; along with instance methods named &quot;initialize&quot; and &quot;say.&quot;
47+
<p>In this example, we want to use a helper function to make a class named <code>Person</code>, along with instance methods named <code>initialize</code> and <code>say</code>.
4848
This is similar to how some popular frameworks handle class creation.</p>
4949
<figure>
5050
<figcaption>Example class</figcaption><pre class="prettyprint lang-js"><code>// We want to document this as being a class
@@ -61,54 +61,80 @@ <h2 id="examples">Examples</h2>
6161
);
6262
</code></pre>
6363
</figure>
64-
<p>Without any comments, JSDoc won&#39;t recognize that this code creates a &quot;Person&quot; class with two methods. To document the methods, we must use a &quot;@lends&quot;
65-
tag in a doc comment immediately before the object literal. The @lends tag tells JSDoc that all the member names of that object literal are being &quot;lent&quot;
66-
to a variable named &quot;Person.&quot;</p>
64+
<p>Without any comments, JSDoc won&#39;t recognize that this code creates a <code>Person</code> class with two methods. To document the methods, we must use a <code>@lends</code> tag in a doc comment immediately before the object literal. The <code>@lends</code> tag tells JSDoc that all the member names of that object literal are being
65+
&quot;loaned&quot; to a variable named <code>Person</code>. We must also add comments to each of the methods.</p>
6766
<p>The following example gets us closer to what we want:</p>
6867
<figure>
6968
<figcaption>Documented as static methods</figcaption><pre class="prettyprint lang-js"><code>/** @class */
7069
var Person = makeClass(
7170
/** @lends Person */
7271
{
72+
/**
73+
* Create a `Person` instance.
74+
* @param {string} name - The person's name.
75+
*/
7376
initialize: function(name) {
7477
this.name = name;
7578
},
79+
/**
80+
* Say something.
81+
* @param {string} message - The message to say.
82+
* @returns {string} The complete message.
83+
*/
7684
say: function(message) {
7785
return this.name + " says: " + message;
7886
}
7987
}
8088
);
8189
</code></pre>
8290
</figure>
83-
<p>Now the functions named &quot;initialize&quot; and &quot;say&quot; will be documented, but they appear as static methods of the &quot;Person&quot; class. That
84-
is possibly what you meant, but in this case we want &quot;initialize&quot; and &quot;say&quot; to belong to the instances of the &quot;Person&quot; class.
85-
So we change things slightly by lending the methods to the class&#39;s prototype:</p>
91+
<p>Now the functions named <code>initialize</code> and <code>say</code> will be documented, but they appear as static methods of the <code>Person</code> class.
92+
That is possibly what you meant, but in this case we want <code>initialize</code> and
93+
<code>say</code> to belong to the instances of the <code>Person</code> class. So we change things slightly by lending the methods to the class&#39;s prototype:</p>
8694
<figure>
8795
<figcaption>Documented as instance methods</figcaption><pre class="prettyprint lang-js"><code>/** @class */
8896
var Person = makeClass(
8997
/** @lends Person.prototype */
9098
{
99+
/**
100+
* Create a `Person` instance.
101+
* @param {string} name - The person's name.
102+
*/
91103
initialize: function(name) {
92104
this.name = name;
93105
},
106+
/**
107+
* Say something.
108+
* @param {string} message - The message to say.
109+
* @returns {string} The complete message.
110+
*/
94111
say: function(message) {
95112
return this.name + " says: " + message;
96113
}
97114
}
98115
);
99116
</code></pre>
100117
</figure>
101-
<p>One final step: Our class framework uses the loaned &quot;initialize&quot; function to construct Person instances, but a Person instance does not have its own
102-
&quot;initialize&quot; method. The solution is to add the @constructs tag to the loaned function. Remember to remove the @class tag as well, or else two classes
103-
will be documented.</p>
118+
<p>One final step: Our class framework uses the loaned <code>initialize</code> function to construct <code>Person</code> instances, but a <code>Person</code> instance
119+
does not have its own <code>initialize</code> method. The solution is to add the <code>@constructs</code> tag to the loaned function. Remember to remove the
120+
<code>@class</code> tag as well, or else two classes will be documented.</p>
104121
<figure>
105122
<figcaption>Documented with a constructor</figcaption><pre class="prettyprint lang-js"><code>var Person = makeClass(
106123
/** @lends Person.prototype */
107124
{
108-
/** @constructs */
125+
/**
126+
* Create a `Person` instance.
127+
* @constructs
128+
* @param {string} name - The person's name.
129+
*/
109130
initialize: function(name) {
110131
this.name = name;
111132
},
133+
/**
134+
* Say something.
135+
* @param {string} message - The message to say.
136+
* @returns {string} The complete message.
137+
*/
112138
say: function(message) {
113139
return this.name + " says: " + message;
114140
}

0 commit comments

Comments
 (0)
0