diff --git a/README.md b/README.md index 2f0dd74..2c1ea68 100644 --- a/README.md +++ b/README.md @@ -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