title: How to use confirm alert and return an AJAX promise?
body: <p>I have an existing function that returns an AJAX promise. I want to update this function to display a confirmation alert before running the AJAX call, but other parts of the code use this function and is already expecting a promise.</p>
  
  <p>Here's what my original function looks like:</p>
  
  <pre><code>function doTheDeed() {
    return $.ajax({
      url: '/api/delete/123',
      method: 'POST'
    }).done(function () {
      alert('The deed is done.');
    });
  }
  
  doTheDeed().done(function {} { /*Do something else*/ });
  </code></pre>
  
  <p>Now I want to confirm with the user before running the AJAX call. How do maintain the API agreement of returning a promise, while waiting for the users confirmation or cancel?</p>
  
  <pre><code>function doTheDeed() {
    bootbox.confirm('Are you sure?', function (result) {
      if (result) {
        // Too late to return a promise, promise should've been returned a long time ago
        return $.ajax({
          url: '/api/delete/123',
          method: 'POST'
        }).done(function () {
          alert('The deed is done.');
        });
      } else {
        //return what??
      }
    });
  }
  
  doTheDeed().done(function {} { /*Do something else*/ });
  </code></pre>
  
  <p>Do I need to conditionally return different promises based on the user's response?</p>