Guest User

Untitled

a guest
Apr 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. function MovesWithPromises () {
  2. this.up = function (val) {
  3. new Promise((resolve) => {
  4. this.state.y += val;
  5. resolve();
  6. });
  7. return this;
  8. };
  9.  
  10. this.down = function (val) {
  11. new Promise((resolve) => {
  12. this.state.y -= val;
  13. resolve();
  14. });
  15. return this;
  16. };
  17.  
  18. this.right = function (val) {
  19. new Promise((resolve) => {
  20. this.state.x += val;
  21. resolve();
  22. });
  23. return this;
  24. };
  25.  
  26. this.left = function (val) {
  27. new Promise((resolve) => {
  28. this.state.x -= val;
  29. resolve();
  30. });
  31. return this;
  32. };
  33.  
  34. this.print = function () {
  35. return `x: ${this.state.x}, y: ${this.state.y}`;
  36. };
  37.  
  38. this.state = {
  39. x: 0,
  40. y: 0,
  41. };
  42. }
Add Comment
Please, Sign In to add comment