Src/core/decorators/autobind/autobind

autobind

autobind(_target, propertyKey, descriptor): PropertyDescriptor

Decorator that automatically binds a method to its class instance.
This is useful when passing methods as callbacks to preserve the correct this context.

Parameters

Name Type
_target object
propertyKey string
descriptor PropertyDescriptor

Returns

PropertyDescriptor

Example

class MyComponent {
  @autobind
  handleClick() {
    console.log(this); // Always refers to MyComponent instance
  }
}

const component = new MyComponent();
const button = document.createElement('button');
button.addEventListener('click', component.handleClick); // `this` is correctly bound

Defined in

jodit/src/core/decorators/autobind/autobind.ts:33