title: Sending data between jquery deferred objects
body: <p>I'm trying to grasp deferred objects in jquery but keep running in trouble. Basically I have a series of functions I want to run where the result from function 1 dictates the logic in a second function.</p>
  
  <p>I'm not sure if I have to invoke a pipe method somewhere or just use then() but either way I keep failing. If you look at the first function there is a object named data which is I want to pass to the second.</p>
  
  <pre><code> function run() {
      var data1 = {};
      var data2 = {};
  
      var body = $('body');
  
      $.when(first()).then(second()).done(constructData);
  
      function first() {
          var d = new $.Deferred();
  
  
  
          var data = {} //arbitrary data set that i want to send to second
  
          data.message = 'first message';
          data.id = 1234;
  
          body.append('First done');
  
          //return data object? add it to the resolve method?
         d.resolve();
      }
  
      function second(data) { //how do I get this data object?
  
          var d = new $.Deferred();
  
  
          body.append('Data from first:');
  
           body.append('Second done');
  
          d.resolve();
      }
      function constructData() {
  
      }
  
  }
  </code></pre>