Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MovesWithPromises () {
- this.up = function (val) {
- new Promise((resolve) => {
- this.state.y += val;
- resolve();
- });
- return this;
- };
- this.down = function (val) {
- new Promise((resolve) => {
- this.state.y -= val;
- resolve();
- });
- return this;
- };
- this.right = function (val) {
- new Promise((resolve) => {
- this.state.x += val;
- resolve();
- });
- return this;
- };
- this.left = function (val) {
- new Promise((resolve) => {
- this.state.x -= val;
- resolve();
- });
- return this;
- };
- this.print = function () {
- return `x: ${this.state.x}, y: ${this.state.y}`;
- };
- this.state = {
- x: 0,
- y: 0,
- };
- }
Add Comment
Please, Sign In to add comment