Guest User

Untitled

a guest
Nov 21st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. function Future(promise){
  2. var result;
  3. promise.then(function(res){
  4. result = res;
  5. });
  6. Object.defineProperties(this, {
  7. value: {
  8. get: function(){
  9. return result;
  10. }
  11. }
  12. });
  13. }
  14.  
  15. var a = new Promise(function(resolve, reject){
  16. setTimeout(function(){resolve('Hello, Future');}, 500);
  17. });
  18. var b = new Future(a);
  19. console.log('first call: %s', b.value);
  20. setTimeout(function(){
  21. var c = b.value;
  22. console.log(c);
  23. }, 1000);
  24. console.log('second call: %s', b.value);
Add Comment
Please, Sign In to add comment