
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
bind-decorator
Advanced tools
Context method binding decorator.
@bind
is just a little faster version of @autobind
for decorating methods only, by binding them to the current context. It is written in TypeScript and follows the latest decorator
s proposal.
throw
exceptions if decorating anything other than function
;decorator
s proposal where compartion betweeen this
and target
can not be trusted, @bind
will always return
a configurable
, get accessor propertyDescriptor
which will memomize the result of descriptor.value.bind(this)
by re-defining the property descriptor of the method beeing decorated (Credits goes to autobind-decorator for memoizing the result).If you are looking for not just method decorator but rather full class bounding decorator check @autobind
.
Install with npm:
$ npm install bind-decorator
import bind from 'bind-decorator';
class Test {
static what = 'static';
@bind
static test() {
console.log(this.what);
}
constructor(what) {
this.what = what;
}
@bind
test() {
console.warn(this.what);
}
}
const tester = new Test('bind');
const { test } = tester;
tester.test(); // warns 'bind'.
test(); // warns 'bind'.
Test.test(); // logs 'static'.
import bind from 'bind-decorator';
class Test {
public static what: string = 'static';
@bind
public static test(): void {
console.log(this.what);
}
public constructor(public what: string) {
this.what = what;
}
@bind
public test(): void {
console.warn(this.what);
}
}
const tester: Test = new Test('bind');
const { test } = tester;
tester.test(); // warns 'bind'.
test(); // warns 'bind'.
Test.test(); // logs 'static'.
npm install
npm test
npm install
Make changes
If necessary add some tests to __tests__
npm test
Make a Pull Request
FAQs
The fastest automatic method.bind(this) decorator
The npm package bind-decorator receives a total of 84,728 weekly downloads. As such, bind-decorator popularity was classified as popular.
We found that bind-decorator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.