Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tswayne/class-bindall
BindAll specifically for javascript classes
https://github.com/tswayne/class-bindall
Last synced: about 1 month ago
JSON representation
BindAll specifically for javascript classes
- Host: GitHub
- URL: https://github.com/tswayne/class-bindall
- Owner: tswayne
- Created: 2018-08-25T22:23:36.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-25T22:26:41.000Z (about 6 years ago)
- Last Synced: 2024-09-24T02:44:15.479Z (about 2 months ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Class bindall
A bindall method specifically for classes. Can dynamically bind all class methods to instance, or a select set.
The resulting bound methods are also logged properly (unlike lodash's bindall) in performance monitoring and profiling tools such as Newrelic or nodes native profiler.nodes native profiler.
## Usage
#### Dynamic
```
const bindAll = require('class-bindall')class MyClass {
constructor() {
// methodA and methodB are automatically bound to the instance
bindAll(this)
}methodA() {
console.log('A')
}methodB() {
console.log('B')
}
}```
#### Manual
```
const bindAll = require('class-bindall')class MyClass {
constructor() {
// only methodB is bound to the instance
bindAll(this, ['methodB'])
}methodA() {
console.log('A')
}methodB() {
console.log('B')
}
}
```