Module @knicola/autobind - v0.1.1

@knicola/autobind

Automatically bind all methods of an object to the object itself.

Install

Using npm:

$ npm install @knicola/autobind

Using yarn:

$ yarn add @knicola/autobind

Usage

import { autobind } from '@knicola/autobind'

// with autobind
class Foo {
public myname: string = 'foo'
constructor() {
autobind(this)
}
public say(): void {
console.log(this.myname)
}
}
const { say: sayFoo } = new Foo()
sayFoo() //=> "foo"

// without autobind
class Bar {
public myname: string = 'bar'
public say(): void {
console.log(this.myname)
}
}
const { say: sayBar } = new Bar()
sayBar() //=> [ERR]: this is undefined

License

This project is open-sourced software licensed under the MIT license.

Index

Functions

Generated using TypeDoc