-
-
Save chuck0523/177d52ba24e021a1c507 to your computer and use it in GitHub Desktop.
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
//Rest Parameters | |
rest(1,2,3); | |
function rest(...args){ | |
console.log(args); // [1, 2, 3] | |
console.log(arguments); // [1, 2, 3] | |
console.log(Array.isArray(args)); //true | |
console.log(Array.isArray(arguments)) //false | |
args.forEach(x => console.log(x)); //1 2 3 | |
arguments.forEach(x => console.log(x)); //Error | |
} | |
function rest(x, y, ...others) { | |
console.log(x, y, others); | |
} | |
rest(1, 2, 3); // 1 2 [3] | |
//引数が渡らなかった場合は空の配列になる | |
rest(1); //1 undefined [] | |
//最後の引数以外には使用できない | |
function rest(first, ...arr, last) { } //NG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment