Edit in JSFiddle

function delay (timeout) {
  var d = Q.defer();
  setTimeout(d.resolve, timeout);
  return d.promise;
}

delay(1000).then(function () {
  alert('a');
});

              
            
          
            
              
                

              
            
          
            
              

External resources loaded into this fiddle: