You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The binding for fat arrow is lost if you wrap class method with some function. I demonstrate it with async example, but it's not tied to it, the behaviour will be the same for any other function too.
classEventshandle:async (event) =>console.log@
Will produce (note the this is lost, actually it's not even lost but completely wrong, the Events is used instead of this):
The title of your issue is confusing. This isn’t really an “async method”, it just happens to be that you’re passing a method as an argument to a function named async.
Activity
[-]Wrong class code-generation for async methods[/-][+]Fat arrow method doesn't work for async methods[/+][-]Fat arrow method doesn't work for async methods[/-][+]Fat arrow doesn't work for async methods[/+]thinkingofmaud commentedon Oct 31, 2016
That's intended. The fat arrow syntax expresses a function that inherits the context from the outer expression.
Inside a class declaration, the context is the class itself.
I think the syntax for
is wrong, but that should break some old code.
assuming async is a decorator function, you may write your code as
so the fat arrow expression is written inside the instance context, that I assume is the one you want to pass along.
GeoffreyBooth commentedon Oct 31, 2016
The title of your issue is confusing. This isn’t really an “async method”, it just happens to be that you’re passing a method as an argument to a function named
async.We’re working on true async support in #3757.