Gathering detailed insights and metrics for ts-class-autobind
Gathering detailed insights and metrics for ts-class-autobind
Gathering detailed insights and metrics for ts-class-autobind
Gathering detailed insights and metrics for ts-class-autobind
npm install ts-class-autobind
Typescript
Module System
Node Version
NPM Version
48.7
Supply Chain
83.4
Quality
69.4
Maintenance
25
Vulnerability
96.1
License
TypeScript (100%)
Total Downloads
7,389
Last Day
2
Last Week
6
Last Month
37
Last Year
580
ISC License
4 Stars
102 Commits
7 Branches
1 Contributors
Updated on Mar 08, 2023
Minified
Minified + Gzipped
Latest Version
0.3.2
Package Id
ts-class-autobind@0.3.2
Unpacked Size
52.90 kB
Size
12.76 kB
File Count
37
NPM Version
6.14.5
Node Version
12.18.2
Cumulative downloads
Total Downloads
Last Day
100%
2
Compared to previous day
Last Week
-76%
6
Compared to previous week
Last Month
-7.5%
37
Compared to previous month
Last Year
-13.4%
580
Compared to previous year
Based on class-autobind package.
This package provides a single function, autobind
, for use within a constructor to bind all methods to the instance itself.
For example, this allows us to pass a method to an event handler element.addEventListener('click', this.onClick)
and be sure the onClick
method will always be called with the right context.
Note: This has some specific logic for React, but could be used in any project.
TypeScript 3.0 or higher
npm install --save ts-class-autobind
1import { autobind } from "ts-class-autobind"; 2 3class MyComponent extends React.Component { 4 constructor() { 5 super(...arguments); 6 autobind(this); 7 } 8 render() { 9 return <button onClick={this.onClick}>Click Me</button>; 10 } 11 onClick() { 12 console.log("Button Clicked"); 13 } 14}
If your component will possibly be subclassed (you really should not do this, but some third-party libraries like react-css-modules do so) then you will need to specify which prototype will be the source of methods that are to be automatically bound.
1import { autobind } from "ts-class-autobind"; 2 3class MyComponent extends React.Component { 4 constructor() { 5 super(...arguments); 6 autobind(this, MyComponent.prototype); // Note the second parameter. 7 } 8 render() { 9 /* ... */ 10 } 11} 12 13class MySubClassedComponent extends MyComponent { 14 /* This is probably a very bad idea. */ 15}
This software is BSD Licensed.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
11 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More