Comparing version 0.0.2 to 0.0.3
24
index.js
@@ -15,2 +15,3 @@ | ||
// Async function call | ||
module.exports = function() { | ||
@@ -21,2 +22,15 @@ var cb = getLast(slice.call(arguments)) | ||
// Apply given arguments to each callback found | ||
module.exports.with = function() { | ||
var args = slice.call(arguments) | ||
return function() { | ||
var cb = getLast(slice.call(arguments)) | ||
if (cb) process.nextTick(function() { | ||
cb.apply(cb, args) | ||
}) | ||
} | ||
} | ||
// Sync function call | ||
module.exports.sync = function() { | ||
@@ -26,1 +40,11 @@ var cb = getLast(slice.call(arguments)) | ||
} | ||
// Apply arguments, sync | ||
module.exports.withSync = function() { | ||
var args = slice.call(arguments) | ||
return function() { | ||
var cb = getLast(slice.call(arguments)) | ||
if (cb) cb.apply(cb, args) | ||
} | ||
} |
{ | ||
"name": "call-last" | ||
, "author": "Beau Sorensen <mail@beausorensen.com> (http://github.com/sorensen)" | ||
, "version": "0.0.2" | ||
, "version": "0.0.3" | ||
, "license": "MIT" | ||
@@ -6,0 +6,0 @@ , "keywords": ["callback"] |
@@ -33,2 +33,10 @@ call-last | ||
something.method = callLast.sync | ||
// bind some arguments | ||
var callWith = callLast.with('hello', 'world') | ||
callWith(1, 2, function(a, b) { | ||
console.log(a) // 'hello' | ||
console.log(b) // 'world' | ||
}) | ||
``` |
20
test.js
'use strict'; | ||
var assert = require('assert') | ||
var info = require('./package.json') | ||
, assert = require('assert') | ||
, ase = assert.strictEqual | ||
describe('call-last', function() { | ||
describe(info.name + ' - v' + info.version, function() { | ||
var last = require('./index') | ||
@@ -19,2 +21,16 @@ | ||
it('with', function(done) { | ||
var check = 0 | ||
, callWith = last.with(null, 'hello') | ||
callWith(done, done, 2, 4, function(err, str) { | ||
check = 1 | ||
ase(err, null) | ||
ase(str, 'hello') | ||
done() | ||
}) | ||
assert.strictEqual(check, 0) | ||
}) | ||
it('sync', function(done) { | ||
@@ -21,0 +37,0 @@ var check = 0 |
4826
73
42