Created
December 10, 2013 11:58
-
-
Save gnab/7889522 to your computer and use it in GitHub Desktop.
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
function sum (...args) { | |
return args.reduce((a, b) => a + b, 0); | |
} | |
var nums = [1,2,3]; | |
// ES5 | |
console.log('sum.apply(null, nums) =', sum.apply(null, nums)); | |
// => sum.apply(null, nums) = 6 | |
console.log('sum(...nums) =', sum(...nums)); | |
// => sum(...nums) = 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment