Skip to content

ogt/arg1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Function wrapper that exposes 1st arg

Build Status

Synopsis

The module is just a couple lines of code

function arg1(func, obj) {
  if (obj) func = func.bind(obj);
  return function(arg) { return func(arg); };
}

The library allows more compact code as seen below :

// this code
list.forEach(function(el) {
  console.log(el);
});

// becomes
list.forEach(arg1(console.log));

// this code
regex = /foo/;
filtered = list.filter(function(el) {
  return regex.test(el);
});

//becomes
regex = /foo/;
filtered = list.filter(arg1(regex.test,regex));

This function could be part of a callback utilities module - I wasn't able to find it in npm

#Description Using this module:

var arg1 = require('arg1');
['Hello','World','!'].map(arg1(console.log));

Installation

Installing the module

npm install arg1

About

Function wrapper that only passes 1st argument to function

Resources

License

Stars

Watchers

Forks

Packages

No packages published