@shanedaugherty/bind-methods
v1.0.3
Published
Bind methods is a simple helper function used to bind a context to multiple class or prototype methods at once.
Downloads
2
Readme
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
/>
)
}
}