Created
August 6, 2015 04:00
-
-
Save craigpalermo/b89f2971c4107233d7b8 to your computer and use it in GitHub Desktop.
JavaScript example of using promises and callbacks
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
var promiser = function (callback) { | |
var promise = new Promise(function(resolve, reject){ | |
console.log("Promise created"); | |
window.setTimeout(function(){ | |
resolve("Hello from Promise Land"); | |
}, 3000); | |
}); | |
promise.then(function(){ | |
callback(); | |
}); | |
}; | |
var myCallback = function () { | |
console.log("Promise resolved"); | |
}; | |
promiser(myCallback); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment