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: docs/RECIPES.md
+38
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,44 @@ class Table {
37
37
}
38
38
```
39
39
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
+
constSelectionEngine=declare(
58
+
null,
59
+
/**@lendsSelectionEngine*/ {
60
+
/**
61
+
* This method will be parsed as SelectionEngine.expandColsTo
62
+
* because the object that contains it has a @lendstag 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
+
40
78
## Destructuring Parameters
41
79
42
80
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