Created
November 20, 2015 00:36
-
-
Save sebdeckers/2f5aaed55dde3a33c10a to your computer and use it in GitHub Desktop.
function arguments: array destructuring vs spread operator
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
var combos = [ | |
[1, 2, 3], | |
[4, 5, 6], | |
[7, 8, 9] | |
] | |
/* function destructures arguments */ | |
function checkWinning ([x, y, z]) { | |
console.log(x, y, z) | |
} | |
combos.forEach(checkWinning) | |
/* pass arguments one by one with spread */ | |
function checkWinning (x, y, z) { | |
console.log(x, y, z) | |
} | |
combos.forEach(combo => checkWinning(...combo)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment