Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrow Methods incorrectly highlighted as bad code? #1457

Closed
greggman opened this issue May 17, 2019 · 6 comments
Closed

Arrow Methods incorrectly highlighted as bad code? #1457

greggman opened this issue May 17, 2019 · 6 comments

Comments

@greggman
Copy link

Arrow methods are apparently a shipping thing

A normal class

class Foo {
   someMethod() {
   }
}

An arrow class method

class Bar {
   someMethod = () => {
   }
}

this is apparently a shortcut for binding the method to the instance. In other words if I understand correctly it's a shortcut for this

class Bar {
   constructor() {
      this.someMethod = this.someMethod.bind(this);
   }
   someMethod{
   }
}

It's already working in Chrome but JSFiddle is marking it as bad code

Screen Shot 2019-05-18 at 0 25 46

Note: It doesn't work in Firefox Nightly nor Safari Tech Preview so maybe I'm jumping the gun here.

@oskarkrawczyk
Copy link
Member

oskarkrawczyk commented May 17, 2019

I can't seem to find a ECMA proposal for this, nor a list of browsers that plan to support it.

@greggman Any chance you have it somewhere?

Worth asking if @jshint will be willing to add it to the linter.

@greggman
Copy link
Author

It falls out of this proposal

https://github.com/tc39/proposal-class-fields

In particular this section

https://github.com/tc39/proposal-class-fields#execution-of-initializer-expressions

says points out they're basically field declarations and they're evaluated anytime the class is constructed/intialized

They've been shipping since Chrome 72

https://developers.google.com/web/updates/2019/01/nic72#public-class-fields

@greggman
Copy link
Author

Note that private class fields also shipped

https://developers.google.com/web/updates/2019/04/nic74#private-class-fields

@greggman
Copy link
Author

browsers: Chrome, Opera, Edge(Chromium Version), Firefox, Safari

@oskarkrawczyk
Copy link
Member

Note to self:

Update JSHint if this ticket is closed: jshint/jshint#3139

@stale
Copy link

stale bot commented Feb 10, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-archived label Feb 10, 2022
@stale stale bot closed this as completed Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants