DEV Community

DotLasher001
DotLasher001

Posted on • Edited on

BewareNote!

Avoid using arrow functions for object methods

If you need to access the object's properties or methods inside a function, using an arrow function might lead to unexpected behavior due to the this binding. Regular functions are often preferred for methods within objects

Image description

Global context: In arrow functions, this retains the value from the surrounding context. This means that in a global context, this inside an arrow function will refer to the global object (window in browsers), which might not always be the desired behavior.

Image description

Binding: If you want to bind a specific context to an arrow function, you can't use .bind() like you can with regular functions. Instead, you might need to create a closure that captures the desired context.

tata bbye!!!πŸš€πŸ˜‰

Top comments (0)