Created
February 10, 2015 23:27
-
-
Save getify/661f707f05e2743d00d2 to your computer and use it in GitHub Desktop.
param spread helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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