Skip to content

Commit

Permalink
Update advanced_examples.md (#230)
Browse files Browse the repository at this point in the history
The docs can be misleading for people who use this example. 

Arrow functions do not expose an 'arguments' object, the only reason the example works is due to babel.

A better example is to use the correct es6 syntax, by using rest parameters.
  • Loading branch information
eladchen authored and FredyC committed Sep 12, 2016
1 parent e9c282e commit 4e2f6b5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/advanced_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ const JoiPrevalidator = stampit
.init(function () { // This will be called for each new object instance.
_.forOwn(this.prevalidations, (value, key) => { // overriding functions
const actualFunc = this[key];
this[key] = () => { // Overwrite a real function with ours.
this[key] = ( ...args ) => { // Overwrite a real function with ours.
const result = joi.validate(this, value, {allowUnknown: true});
if (result.error) {
throw new Error(`Can't call ${key}(), prevalidation failed: ${result.error}`);
}

return actualFunc.apply(this, arguments);
return actualFunc.apply(this, args);
}
});
});
Expand Down

0 comments on commit 4e2f6b5

Please sign in to comment.