Skip to content

Instantly share code, notes, and snippets.

@gnab
Created December 10, 2013 11:58
Show Gist options
  • Save gnab/7889522 to your computer and use it in GitHub Desktop.
Save gnab/7889522 to your computer and use it in GitHub Desktop.
Spread operator.
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