This question is not for asking why arrow functions don't have argument object. I'm happy to use non arrow functions as well. All I want to do is a wrapper function that can pass parameters/arguments to the real function. The example below just happens to use arrow functions. JUST EXAMPLES.
I have a class User which has a number of methods. Before calling these methods, I want to do a check. If it fails, it throws an error. How to pass the arguments to the real methods.
User._checkAndAction = (fn) => {
return () => {
let args = arguments;
if (aSeriousCheck) {
throw new UserError();
} else {
return fn.apply(User, args);
}
}
}
/**
* This gets the user id
*/
User.get = User._checkAndAction((value) => {
return value;
});
When I call User.get('a parameter'), the parameter is not passed to the real method (value) => value.