README
get-callback.js
Get a callback function from arguments
function printCallback() {
var cb = getCallback(arguments);
console.log(cb.toString());
}
printCallback('foo', {some: 'options'}, function cb(x, y) { return x + y; });
//yields: 'function cb(x, y) { return x + y; }'
This module is useful to create a function which takes a callback as its last argument.
Installation
Package managers
npm
npm install --save get-callback
bower
bower install --save get-callback
Standalone
Download the script file directly.
API
getCallback(args)
args: Array
or array-like object (e.g. arguments
)
Return: Function
It returns the last element of args, when the element is a function.
It throws an error when the last element is not a function.
function cb() {
//... Something to do in the callback
}
(function() {
getCallback(arguments); //=> [Function: cb]
})('foo', {some: 'options'}, cb);
License
Copyright (c) 2014 Shinnosuke Watanabe
Licensed under the MIT LIcense.