Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created June 30, 2015 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/b26242e552db61a60bc8 to your computer and use it in GitHub Desktop.
Save chuck0523/b26242e552db61a60bc8 to your computer and use it in GitHub Desktop.
//Spread operator
//配列の前に...をつけることで展開できる。
var arr = [3, 4, 5];
var nums = [1, 2, ...arr, 6, ...[7]];
console.log(nums);
//[1, 2, 3, 4, 5, 6, 7]
//[3,4,5]と[7]が展開されている
//applyメソッドを使用しなくても良い。
function f(x, y, z) {
console.log(x, y, z);
}
var args = [1, 2, 3];
//ES5
f.apply(null, args); //1 2 3
//ES6
f(...args); //1 2 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment