Class method shorthand return

Brian Ninni ninni.brian at gmail.com
Fri May 5 17:49:43 UTC 2017


I think it might be problematic, since (if it works the same way as arrow
functions currently do) 'this' will refer to the context in which the class
was defined, and not to the instance that the function is attached to. And
if it doesn't need to access the instance, then it doesn't really need to
be an instance method anyway.

However if there was a shorthand for regular functions, then this still
might be solvable by allowing key : value pairs in the class definition.
It's only one more character than your proposal (the ':'), and would allow
for values other than shorthand functions to be defined

class MyClass {
  deleteProfileImage : () -> (...)  //or some other new shorthand for
regular functions
  isMyClass : true
  static myStaticMethod : () =>(...)
}

instead of

class MyClass {
  deleteProfileImage(){
    return ...
  }
}
MyClass.prototype.isMyClass = true
MyClass.myStaticMethod = () => (...)


On Fri, May 5, 2017 at 12:13 PM, somonek <somonek at gmail.com> wrote:

> Hi,
>
> I this return shorthand would be helpful.
>
> class MyClass {
>     deleteProfileImage() => (....)
> }
>
> as we already have this
>
> const myFunction = () => (....);
>
>
> any thoughts?
>
>
> Serghei
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170505/4a0252a5/attachment.html>


More information about the es-discuss mailing list