Rest parameters and extension operators
1.rest parameters
ES6 introduces the rest parameter (in the form of a ... variable name) to get the extra arguments of the function so that the object is not needed arguments . The variable that is paired with the rest parameter is an array that puts the extra arguments into the array.
function Add (... values) {let sum = 0; For (var val of values) { sum + = val; } return sum;} Add (2, 5, 3)//10
The function of the above code add is a summation function that, with the rest parameter, can pass any number of arguments to the function.
2. Extension operators
The extension operator (spread) is a three-point ( ... ). It converts an array or an object to a comma-delimited sequence of arguments.
Log Group console.log (... [1, 2, 3]) 1 2 3console.log (1, ... [2, 3, 4], 5)//1 2 3 4 5[...document.queryselectorall (' div ')]//[<div>, <div>, <div>] on object let { x, Y, ... z} = {x:1, y:2, A:3, B:4};x//1y//2z//{a:3, b:4}
3. Analysis
Rest parameters and extension operators can be understood as inverse
Rest parameters and extension operators