Skip to content

Commit

Permalink
Put provided function in correct context
Browse files Browse the repository at this point in the history
  • Loading branch information
brycebaril committed Aug 7, 2013
1 parent 3aa8152 commit 22051de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions index.js
Expand Up @@ -8,12 +8,14 @@ function ctor(options, fn) {
fn = options
options = {}
}
options._index = 0
return through2.ctor(options, function (chunk, encoding, callback) {

var Map = through2.ctor(options, function (chunk, encoding, callback) {
if (this.options.wantStrings) chunk = chunk.toString()
this.push(fn(chunk, this.options._index++))
this.push(fn.call(this, chunk, this._index++))
return callback()
})
Map.prototype._index = 0
return Map
}

function make(options, fn) {
Expand Down
5 changes: 3 additions & 2 deletions test/index.js
Expand Up @@ -29,9 +29,10 @@ test("ctor", function (t) {
})

test("ctor options", function (t) {
t.plan(2)
t.plan(7)

var Map = map.ctor({objectMode: true}, function (record) {
var Map = map.ctor({objectMode: true, foo: "bar"}, function (record) {
t.equals(this.options.foo, "bar", "can see options")
record.foo.toUpperCase()
return record
})
Expand Down

0 comments on commit 22051de

Please sign in to comment.