monners
1/23/2017 - 9:55 PM

Promise creation example

Promise creation example

function ajaxRequest (url, cb) {
  setTimeout(() => {
    cb({ height: 1000, width: 500});
  }, 2000)
}

const p = new Promise((res, rej) => {
  ajaxRequest('url', (data) => {
    res(data);
  })
});

p.then(data => {
  console.log(data);
});