JSFiddle - React, Tailwind, and code Playground

by Hui Zheng

JavaScript

/*console.time('a');
$.sleep = function(time) {
  return $.Deferred(function(dfd) {
    setTimeout(dfd.resolve, time);
  });
}

$.sleep(1000).then(function() {
    console.timeEnd('a');
  console.log("Hello from the future!");
});*/

console.time('a2');
$.defer = function(time, f) {
    function g(dfd) {
        dfd.resolve();
        console.log('calling');
        f.apply(null, arguments);
    }
  return $.Deferred(function(dfd) {
    setTimeout(g, time, dfd);
  });
}

$.defer(1000, function() {
    console.timeEnd('a2');
  console.log("Hello from the future!");
});