slice-arguments

0.0.1 • Public • Published

slice-arguments

slice arguments and common helpers

Installing

npm install slice-arguments

component install stagas/slice-arguments

Example

var slice = require('slice-arguments');
 
function foo(){
  var args = slice.call(arguments); // or just: slice(arguments)
 
  // get all values except callback if present
  console.log(args.values()); // => [ 'Hello' ]
 
  // get the callback if present
  console.log(args.callback()); // => [Function]
 
  // decorate callback
  var fn = args.callback(function(s){
    fn(+ '!');
  });
 
  bar.apply(this, args);
}
 
function bar(s, fn){
  fn(+ ', world');
}
 
foo('Hello', function(res){
  console.log(res); // => Hello, world!
});

API

slice(arguments)

slice.call(arguments)

Returns arguments in an array.

.callback([fn])

Returns the callback if present, or a noop function, and optionally replaces with fn.

.values()

Returns the arguments minus the callback if present.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i slice-arguments

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • stagas