Idea:
A simple shorthand for foo.bar.bind(foo, ...)
to make it nicer to work with partial function application.
// shorthand
function sillyClone(input) {
var acc = [];
input.forEach(acc.push&());
return acc;
}
// expansion
function sillyClone(input) {
var acc = [];
input.forEach(acc.push.bind(acc));
return acc;
}
More practical/realistic example:
var test = require('tap').test;
var mod = require('../'); // whatever our module is...
test('simple calls', function(t) {
t.throws(mod&(1), MissingArgumentError);
t.throws(mod&(1, 2, 3, 4), TooManyArgumentsError);
t.doesNotThrow(mod&(1, 2, 3), 'just right');
t.end();
});
test('cumbersome calls', function(t) {
t.throws(mod.bind(null, 1), MissingArgumentError);
t.throws(mod.bind(null, 1, 2, 3, 4), TooManyArgumentsError);
t.doesNotThrow(mod.bind(null, 1, 2, 3), 'just right');
t.end();
});
test('arrows', function(t) {
t.throws(()=>{mod(1)}, MissingArgumentError);
t.throws(()=>{mod(1, 2, 3, 4)}, TooManyArgumentsError);
t.doesNotThrow(()=>{mod(1, 2, 3)}, 'just right');
t.end();
});