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

autobind-decorator

Package Overview
Dependencies
Maintainers
2
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

  • 1.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
200K
decreased by-22%
Maintainers
2
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 22 Aug 2015

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