Skip to content
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

Update Advice API doc for event and data params, multiple advice #330

Merged
merged 1 commit into from
Jan 16, 2015
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
35 changes: 35 additions & 0 deletions doc/advice_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,41 @@ function withDrama() {
return withDrama;
```

<a name="notes"></a>
## Additional notes on using Advice

### Retrieving event data

In the above examples, the jQuery event and payload that will be passed to the `existingFunc` are available as extra parameters to the `customFunc` callback, respectively. This can be especially useful for calling `existingFunc` with the original arguments when using `this.around`:

```js
function withMelodiousHumour() {
this.around('yodel', function(func, event, data) {
if (data.tune) {
func(event, data); // event.type == 'yodel'
}
});
}

return withMelodiousHumour;
```

In the above example, `yodel` will never be called if `data.tune` is missing.

### Shorthand for multiple advices

Advice can be applied to multiple functions at once by listing more than one (space-separated) function names in the `existingFuncName` parameter. This can be used to club together common tasks on related methods:

```js
function withSoundCheck() {
this.before('announce yodel trumpet', function (event, data) {
checkOneTwo();
});
}

return withSoundCheck;
```

<a name="advice.withAdvice"></a>
## Making advice available to regular objects

Expand Down