0

We have a situation, like on in the following code:

  if (typeof callback === 'undefined') {
    return aggregate;
  }

  return aggregate.exec(callback); // returns promise

If callback not specified - need to return aggregate, and if specified - return promise.

So if we have promise, then we don't have callback and if (typeof callback === 'undefined') would be true, but i need false, because we have promise

The problem is that i can't find any information about how i can know whether .then() existing or not, can someone point me to the right direction?

UPDATE

Explanation:

  if (typeof callback === 'undefined') { // need to check that we don't have .then()
    return aggregate; // need to return this only if we don't have promise AND callback
  }

  return aggregate.exec(callback); // returns promise

UPDATE2

I can't find any information about my situation - i don't think it's duplicate.

The question is - how can we figure out that .then() exists before creating promise?

alexey
  • 1,381
  • 9
  • 19

0 Answers0