Skip to content

use ES6 syntax #3

@AlbyIanna

Description

@AlbyIanna
Contributor

https://github.com/bcmi-labs/create-plugin-communication/blob/d63b22a9073defb9c7663ea849ee013de09b08a0/src/readMessages.js#L193
@eclipse1985 is there a reason to use this syntax, or we can change it to ES6 --> const deferred = ()=> {...}?

Activity

eclipse1985

eclipse1985 commented on Jun 18, 2018

@eclipse1985

You're right, here Deferred is used as an old-style ES5 contructor. With ES6 you should use classes, but I don't know if you can just rewrite this like an arrow function. I will do some tests.

eclipse1985

eclipse1985 commented on Jun 18, 2018

@eclipse1985

Rewriting Deferred as an arrow function, obviously loses the pointer to the functional this, so the only way to avoid the use of a plain constructor function, is to write a class like this:

class Deferred {
  constructor() {
    this.resolve = null;
    this.reject = null;

    this.promise = new Promise((resolve, reject) => {
      this.resolve = resolve;
      this.reject = reject;
    });
  }
}

what do you think @AlbyIanna ?

AlbyIanna

AlbyIanna commented on Jun 18, 2018

@AlbyIanna
ContributorAuthor

Okay for me.

added
enhancementNew feature or request
and removed
questionFurther information is requested
on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @eclipse1985@AlbyIanna

        Issue actions

          use ES6 syntax · Issue #3 · arduino/arduino-create-agent-js-client