Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/danhper/node-bind-gen

bind for generators
https://github.com/danhper/node-bind-gen

Last synced: about 1 month ago
JSON representation

bind for generators

Awesome Lists containing this project

README

        

# node-bind-gen [![Build Status](https://travis-ci.org/tuvistavie/node-bind-gen.svg)](https://travis-ci.org/tuvistavie/node-bind-gen)

A simple helper function to use `bind` with generator functions.
It works like [lodash](http://lodash.com) `bind` function, or the
built-in `bind`, but takes and returns a generator function
instead of a normal one.

## Installation

```sh
$ npm install bind-gen
```

## Example

```javascript
var co = require('co');
var bindGen = require('bind-gen');

var myGenerator = function *(myArg, myOtherArg) {
console.log(this.v);
console.log(myArg);
console.log(myOtherArg);
};

var context = {v: 'the-context'};
var boundGenerator = bindGen(myGenerator, context, 'arg');

co(boundGenerator('other arg'));
// will print:
// the-context
// arg
// other arg
```