Search code examples
javascriptfunctionpromiseinterceptormethod-modifier

How can one access an unknown executer function from a Promise instance's construction time?


Is it possible to retrieve the implementation details of a Promise instance? Let's assume the following created promise ...

let myPromise = new Promise(function (success, error) {
  /* implementation */
}

Can one somehow access the anonymous function ...

function (success, error) {
  /* implementation */
}

... or get the location of the anonymous function in the code file?


Solution

  • No. The promise object does not contain the code, neither internally nor accessible to JavaScript. A promise represents the result of a task, not the task itself, it is not runnable. The function is used only during construction.