Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

autobind-decorator

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autobind-decorator

Decorator for binding method to an object

  • 2.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
241K
decreased by-1.65%
Maintainers
1
Weekly downloads
 
Created

What is autobind-decorator?

The `autobind-decorator` npm package provides a decorator for automatically binding methods to their class instance. This is particularly useful in JavaScript and TypeScript classes where you want to ensure that methods retain the correct `this` context, especially when passing them as callbacks.

What are autobind-decorator's main functionalities?

Automatic Method Binding

This feature allows you to automatically bind class methods to the instance of the class. In the example, the `getValue` method is bound to the instance of `MyClass`, ensuring that `this.value` correctly refers to the instance's `value` property even when the method is called as a standalone function.

class MyClass {
  constructor() {
    this.value = 42;
  }

  @autobind
  getValue() {
    return this.value;
  }
}

const instance = new MyClass();
const getValue = instance.getValue;
console.log(getValue()); // 42

Other packages similar to autobind-decorator

FAQs

Package last updated on 30 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc