Skip to content

Instantly share code, notes, and snippets.

@getify
Created February 10, 2015 23:27
Show Gist options
  • Save getify/661f707f05e2743d00d2 to your computer and use it in GitHub Desktop.
Save getify/661f707f05e2743d00d2 to your computer and use it in GitHub Desktop.
param spread helper
// thanks to @raganwald
function spread(fn) {
return Function.apply.bind( fn, null );
}
function foo(x,y,z) {
console.log(x,y,z);
}
function bar(fn) {
fn( [1,2,3] );
}
bar( spread( foo ) ); // 1 2 3
// In ES6, we have param destructuring to help
function foo( [x,y,z] ) {
console.log(x,y,z);
}
function bar(fn) {
fn( [1,2,3] );
}
bar( foo ); // 1 2 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment