1.0.0 • Published 10 years ago

get-callback v1.0.0

Weekly downloads
2
License
-
Repository
github
Last release
10 years ago

get-callback.js

Build Status Build status Coverage Status devDependency Status

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 version

npm install --save get-callback

bower Bower version

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.