Skip to content

docs(lends): Document the usage of the lends tag #758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/RECIPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,44 @@ class Table {
}
```

## Class factories: using `@lends`

Many libraries and frameworks have special 'class constructor methods' that
accept an object as an input and return a class with that object's properties
as prototype properties. For instance, Dojo has `define`, React has `React.createClass`,
Ext has `Ext.define`.

documentation.js can't assume that a method receiving an object will return a class,
since many methods don't. Luckily, you can indicate this to the tool with the `@lends`
tag.

For instance in a Dojo-style instantiation:

```js
/**
* This is the documentation for the created class, a SelectionEngine
*/
const SelectionEngine = declare(
null,
/** @lends SelectionEngine */ {
/**
* This method will be parsed as SelectionEngine.expandColsTo
* because the object that contains it has a @lends tag indicating
* that it will be lended to the SelectionEngine prototype.
*/
expandColsTo: function(foo, bar, baz) {}
}
);
```

The mechanics are:

* If you're creating a kind of class with a helper function
* And you provide an object of properties that will be mixed in to the class
as one of the arguments to that function
* Add a tag like `/** @lends ClassName */` before that object, and the properties
in the object will be correctly assigned to the class's prototype.

## Destructuring Parameters

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