Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alorel/bound-decorator
A TypeScript/ES7 decorator for automatically binding methods to the class instance
https://github.com/alorel/bound-decorator
auto babel bind bound decorator es7 method typescript
Last synced: about 2 months ago
JSON representation
A TypeScript/ES7 decorator for automatically binding methods to the class instance
- Host: GitHub
- URL: https://github.com/alorel/bound-decorator
- Owner: Alorel
- License: apache-2.0
- Created: 2019-03-03T13:54:24.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-14T19:31:19.000Z (about 1 year ago)
- Last Synced: 2024-11-01T23:42:26.291Z (2 months ago)
- Topics: auto, babel, bind, bound, decorator, es7, method, typescript
- Language: TypeScript
- Size: 516 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Bound decorator
An ES7 decorator for making class methods bound to the class instance (including statics).
[![MASTER CI status](https://github.com/Alorel/bound-decorator/actions/workflows/core.yml/badge.svg)](https://github.com/Alorel/bound-decorator/actions/workflows/core.yml?query=branch%3Amaster)
[![NPM badge](https://img.shields.io/npm/v/%40aloreljs/bound-decorator)](https://www.npmjs.com/package/%40aloreljs/bound-decorator)
[![dependencies badge](https://img.shields.io/librariesio/release/npm/%40aloreljs/bound-decorator)](https://libraries.io/npm/@aloreljs%2Fbound-decorator)
[![Coverage Status](https://coveralls.io/repos/github/Alorel/bound-decorator/badge.svg)](https://coveralls.io/github/Alorel/bound-decorator)-----
# Table of Contents
- [Installation](#installation)
- [Compatibility](#compatibility)
- [Usage](#usage)# Installation
```
npm install @aloreljs/bound-decorator
```# Compatibility
The library's only goal is to be compatible with Typescript 5 decorators which, at the time of writing, use the [2022-03 stage 3 decorators proposal](https://2ality.com/2022/10/javascript-decorators.html).
# Usage
```javascript
import {BoundMethod} from '@aloreljs/bound-decorator';class MyClass {
@BoundMethod()
method1() {
// equivalent to
// this.method1 = this.method1.bind(this);
}
@BoundMethod('a', 'b')
method2(a, b, c) {
// equivalent to
// this.method2 = this.method2.bind(this, 'a', 'b');
}@BoundMethod()
static foo() {
// Equivalent to
// MyClass.foo = MyClass.foo.bind(MyClass);
}
}
```