1.0.12 • Published 6 years ago

protobind v1.0.12

Weekly downloads
44
License
Apache-2.0
Repository
github
Last release
6 years ago

protobind

Binds all methods on an object to itself, including those defined on its prototype, and inherited up the chain. Also ensures that any methods' properties are preserved.

import autobind from 'protobind';

class Foo {
  constructor() {
    autobind(this);
  }

  foo() {
    return 'stuff';
  }

  bar() {
    return this.foo();
  }
}

const bar = new Foo().bar;
bar(); // 'stuff'

You can also use it as a decorator:

import autobind from 'protobind';

@autobind
class Foo {
  foo() {
    return 'stuff';
  }

  bar() {
    return this.foo();
  }
}

const bar = new Foo().bar;
bar(); // 'stuff'
1.0.12

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.0

6 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.4

8 years ago

1.0.3

8 years ago