Last active
September 23, 2015 23:19
-
-
Save kebman/b4ce755ffa4612f2879f to your computer and use it in GitHub Desktop.
Simple example of a JavaScript Promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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