title: Why functions as arguments (resolve, reject) are used in the Promise syntax rather than a simple return and throw?
body: <p>This is a 'why' question, not a suggestion. I know the following function is incorrect, but it helps to clarify my question: I want to know what is wrong with this view (i.e. what requirement of Promise I am missing here). Answers can help other like me to get out of confusion. Please provide an example where the following requirement of <code>Promise</code> is necessary:</p>
  
  <p>I (incorrectly) assumed Promises are for deferring execution of functions and assigning a chain of then &amp; catch. I need to know the following: Why does JavaScript Promise uses (resolve, reject) instead of a parameter-less callback that returns or throws?</p>
  
  <p>In a naive and incorrect view, the <code>Promise</code> could have been used in a simpler way (without two arguments <code>resolve</code>, <code>reject</code>) like the following:</p>
  
  <pre><code>/*new*/ IncorrectPromise(()=&gt;{
      let x = Math.random()&gt;0.5;
      console.log('promise 1');
      if (x) {
          return 'head1';
      } else {
          throw new Error('tail1');
      }
  })
  .then((d)=&gt;{
      console.log('.then() d=', d);
  })
  .catch( (ex) =&gt;{
      console.log('.catch() e=', ex.message);
  });
  </code></pre>
  
  <p>Instead of the Promise's way:</p>
  
  <pre><code>new Promise( (resolve_, reject_) =&gt; {
      let y = Math.random()&gt;0.5;
      console.log('promise 2');
      if (y) {
          resolve_('head2');
      } else {
          reject_(new Error('tail2'));
      }
  })
  .then((d)=&gt;{
      console.log('              .then() d=', d);
  })
  .catch( (ex) =&gt;{
      console.log('              .catch() e=', ex.message);
  });
  </code></pre>
  
  <p>i.e. when the control flow exits the body of the callback of the promise, resolve or reject are used based on whether the exit was caused by a <code>return</code> or a <code>throw</code>.</p>
  
  <p>My question is, why promises use the current syntax? The answer will be an example which cannot be done with this (naive) function.</p>
  
  <p>The above syntax can be easily emulated with the following definition (for simplicity, ignore the fact that <code>IncorrectPromise</code> is not a constructor, hence does not need the <code>new</code> operator):</p>
  
  <pre><code>function IncorrectPromise(callback) {
      return new Promise( (res, rej) =&gt; {
          try {
              res( callback() );
          } catch (err) {
              rej(err);
          }
      });
  }
  </code></pre>
  
  <p>What would have been the shortcoming of this simpler usage syntax? What was the intention of the designers or the <code>Promise</code> to use (resolve, reject)?</p>