The title of this question is probably misleading. I'm having some trouble wrapping my head around this concept. I want to pass all of the arguments into a function, but call it with those arguments later.
I'm currently doing something like this:
function copyRecords(userId, options) {
const getRecordsWrapper = (userId, options) => () => getRecords(userId, options);
abstractionService = new MyAbstractionService(getRecordsWrapper);
...etc
}
This is where I would save and later call the function:
class MyAbstractionService {
constructor(getRecords) {
this.getRecords = getRecords;
}
performSomeAction() {
return this.getRecords();
}
}
I need to do this because getRecords takes different arguments in different areas, and I want to abstract them into one service without having to pass a bunch of arguments into the service. That will get messy, as I need to do this for some other functions as well.
Am I thinking about this correctly? Is there another way to do this besides having a function return another function which returns my function? Also, not sure if this is important but getRecords returns a Promise. I don't want to start working on the Promise until I'm in the abstraction service later though.
getRecords.