We still need to wrap the method in an arrow function to keep this in the correct context, unfortunately.
this
class myClass { myPrivateVal = "appendedValue"; appendMyPrivateVal(argument) { return argument + ' ' + this.myPrivateVal; } } async function someAsyncMethod() { return new Promise<string>((resolve) => setTimeout(() => resolve("asyncResult"), 1000)); } var myInstance = new myClass(); (async () => { const result = someAsyncMethod().then(myInstance.appendMyPrivateVal); result; // asyncResult undefined const result2 = someAsyncMethod().then((arg) => myInstance.appendMyPrivateVal(arg)); result2; // asyncResult appendedValue })();
I really hate this sometimes.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
We still need to wrap the method in an arrow function to keep
this
in the correct context, unfortunately.I really hate this sometimes.