Skip to content
Open
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ handleResponse('some', 'args') // TypeError: Callback is required

Note the __vargs.strict__ call.

With ES6 default parameters:
vargs-callback uses Function.length to find the correct position for the callback. The length parameter only includes parameters before the first one with a default value so you will need to set the length parameter for functions with default arguments for vargs-callback to work.

```js
var vargs = require('vargs-callback')

function openTheDoor(door, options = {speed: 1} , callback) {
// actual function code using parameters
// options will be {speed: 1} if only door and callback given
if (door.isOpen) return
// ...
}

Object.defineProperty(openTheDoor, 'length', { value: 3 })
openTheDoor = vargs(openTheDoor) // Decorate global function
```

## The Rules

Expand Down