Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/q.js/1.0.1/q.js"></script>
  <script src="https://unpkg.com/promise-sugar"></script>
</head>
<body>
<pre id="out"></pre>
</body>
</html>
 
(async () => {
// -------------------------------------------------------------
  log('--- 1 ---')
  await sweeten(10)
  ((n) => n / 2)
  ((n) => n * 3)
  (log)
  ;
  
// -------------------------------------------------------------
  log('--- 2 ---')
  var a = sweeten('a');
  var b = sweeten('b');
  a(b)(log); // a() also accepts thenable! (not Promise/A+ compliant)
  a("not a thenable")(logError); // and ignores other values, as Promise/A+ does
  await a; // you can still await for a sweeten promise, because it is a thenable!
// -------------------------------------------------------------
})();
// --- Helpers ---
function log(m) {
  out.innerHTML += JSON.stringify(m) + '\n';
  return m;
}
function logError(e) {
  out.innerHTML += '<b class="error" style="color:red">' + JSON.stringify(e) + '</b>\n';
  return m;
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
duzunpro
0viewers