Socket
Socket
Sign inDemoInstall

bind-decorator

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bind-decorator

The fastest automatic method.bind(this) decorator


Version published
Weekly downloads
109K
decreased by-16.45%
Maintainers
1
Weekly downloads
 
Created

What is bind-decorator?

The bind-decorator npm package provides a simple way to bind class methods to the instance of the class. This is particularly useful in JavaScript and TypeScript when dealing with event handlers or callbacks where the context of 'this' can be lost.

What are bind-decorator's main functionalities?

Method Binding

This feature allows you to bind a class method to the instance of the class using the @bind decorator. This ensures that the method retains the correct 'this' context when called.

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

  @bind
  printValue() {
    console.log(this.value);
  }
}

const instance = new MyClass();
const print = instance.printValue;
print(); // Outputs: 42

Other packages similar to bind-decorator

Keywords

FAQs

Package last updated on 20 Sep 2016

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