consider this code
const obj = {
  generate(num) {
    return Math.random()*num;
  },
  add(a,b) {
    return this.generate(a) + this.generate(b)
  }
};
function delay(func, ms) {
  function wrapper() {
    setTimeout(() => func.apply(this, arguments), ms)  // How can I get the return value from the original function?
  }
  return wrapper;
}
// create wrappers
obj.f1000 = delay(obj.add, 1000);
obj.f1500 = delay(obj.add, 1500);
obj.f1000(1,3);
obj.f1500(2,5);
I made a wrapper to delay the method call for add()
Is there a way to retrieve the value from the callback inside setTimeout, i.e. the this.generate(a) + this.generate(b) from add()?
 
     
    