1.0.3 • Published 6 years ago

@shanedaugherty/bind-methods v1.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

Bind Methods

Bind methods is a simple helper function used to bind a context to multiple class or prototype methods at once.

It was created primarily for use with React Components, but has no dependencies on React.

Parameters

Methods

type: Array

An array of methods names (strings). Each will be used to access the method magically like so: context['method'].

Context

type: Object, *

The context that shall be bound to each method.

Example usage with React

class extends React.Component {
  constructor() {
    super();
    bindMethods(['someFunction', 'anotherFunction'], this);
  }
  
  someFunction() {...};
  
  anotherFunction() {...};
  
  render() {
    return (
      <ChildComponent 
        someFunction={this.someComponent} // context will be bound 
      />
    )
  }
}