79162783

Date: 2024-11-06 13:29:50
Score: 0.5
Natty:
Report link

I understand that arrow functions have a lexical this binding

Yes.

but I was hoping .call or .apply would still allow me to change the context.

No. It's purely lexical.

Can someone explain why this is happening

That is how arrow functions are designed

or suggest an alternative approach?

Don't use an arrow function if you don't want lexical binding. Lexical binding is the point of arrow functions.

var obj = {
  method() {
    console.log(this)
  }
}

obj.method();

Reasons:
  • RegEx Blacklisted phrase (2.5): Can someone explain
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • High reputation (-2):
Posted by: Quentin