Skip to content

Instantly share code, notes, and snippets.

@kebman
Last active September 23, 2015 23:19
Show Gist options
  • Save kebman/b4ce755ffa4612f2879f to your computer and use it in GitHub Desktop.
Save kebman/b4ce755ffa4612f2879f to your computer and use it in GitHub Desktop.
Simple example of a JavaScript Promise
<!DOCTYPE html>
<html>
<head>
<title>Promises in HTML5 + ES6</title>
<meta charset="utf-8">
</head>
<body>
<header>
<h1>Promises in HTML5 + ES6</h1>
</header>
<article>
<h1>Test Area</h1>
<p id="pub"></p>
<p>See source code for how the JavaScript works.</p>
</article>
</body>
<script>
function makeAPromise(){
return Promise.resolve("Promised value :)");
}
function pubit(input) {
return pub.innerHTML = input; // var pub = getElementById('pub') is inferred
}
makeAPromise().then(pubit);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment