get-callback

1.0.0 • Public • Published

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.

Package Sidebar

Install

npm i get-callback

Weekly Downloads

1

Version

1.0.0

License

none

Last publish

Collaborators

  • shinnn