@shanedaugherty/bind-methods
Bind methods is a simple helper function used to bind a context to multiple class or prototype methods at once.
Last updated 2 years ago by shanedaugherty .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @shanedaugherty/bind-methods 
SYNC missed versions from official npm registry.

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 
      />
    )
  }
}

Current Tags

  • 1.0.3                                ...           latest (2 years ago)

4 Versions

  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |