title: JavaScript Promise/Defer in Chrome
body: <p>I use the Q library that supports the Promise specification well. But I also try to use the Promise class that has been implemented in Chrome not long ago (experimentally). </p>
  
  <p>There's the defer function in Q that can be used for creating a non-fulfilled promise that can be resolved or rejected in the future.</p>
  
  <p>I've implemented the same functionality using the native Promise presented in Chrome. Here's an example:</p>
  
  <pre><code>var defer = function() {
      var result = {};
      result.promise = new Promise(function(resolve, reject) {
          result.resolve = function(value) {
              resolve(value);
          };
          result.reject = function(value) {
              reject(value);
          };
      });
      return result;
  };
  
  var deferred = defer();
  deferred.promise.then(function(value) {
      alert(value);
  });
  deferred.resolve(10);
  </code></pre>
  
  <p>I'm curious is there any design flaw in this solution such as performance slowdown or incorrectness. </p>