Skip to content

Commit 2c19809

Browse files
committed
docs(lends): Document the usage of the lends tag
This tag is useful for documenting class factories in libraries and frameworks Refs #412
1 parent a2f13d6 commit 2c19809

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/RECIPES.md

+38
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,44 @@ class Table {
3737
}
3838
```
3939

40+
## Class factories: using `@lends`
41+
42+
Many libraries and frameworks have special 'class constructor methods' that
43+
accept an object as an input and return a class with that object's properties
44+
as prototype properties. For instance, Dojo has `define`, React has `React.createClass`,
45+
Ext has `Ext.define`.
46+
47+
documentation.js can't assume that a method receiving an object will return a class,
48+
since many methods don't. Luckily, you can indicate this to the tool with the `@lends`
49+
tag.
50+
51+
For instance in a Dojo-style instantiation:
52+
53+
```js
54+
/**
55+
* This is the documentation for the created class, a SelectionEngine
56+
*/
57+
const SelectionEngine = declare(
58+
null,
59+
/** @lends SelectionEngine */ {
60+
/**
61+
* This method will be parsed as SelectionEngine.expandColsTo
62+
* because the object that contains it has a @lends tag indicating
63+
* that it will be lended to the SelectionEngine prototype.
64+
*/
65+
expandColsTo: function(foo, bar, baz) {}
66+
}
67+
);
68+
```
69+
70+
The mechanics are:
71+
72+
* If you're creating a kind of class with a helper function
73+
* And you provide an object of properties that will be mixed in to the class
74+
as one of the arguments to that function
75+
* Add a tag like `/** @lends ClassName */` before that object, and the properties
76+
in the object will be correctly assigned to the class's prototype.
77+
4078
## Destructuring Parameters
4179

4280
In ES6, you can use [destructuring assignment in functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment):

0 commit comments

Comments
 (0)