Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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')
}
}
```