es6--擴充套件運算子
阿新 • • 發佈:2020-07-18
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script> /** *擴充套件運算子 * * */ function show(...a) { console.log("a", a); } //收縮 show(1, 2, 3, 4) //展開 let arr = [1, 2, 3, 4]; console.log("arr", ...arr); //剩餘預算符 function add(a, b, ...c) { console.log("add", a, b, c); } add(1, 2, 3, 4) //物件不可以 // let obj = { // a: 1, // b: 2, // c: 3 // } // console.log("obj", ...obj); let arrb = [...arr];//複製陣列 //箭頭函式沒有arguments物件 //箭頭函式改變this的作用域 //引數物件可以用...args //箭頭函式不能當建構函式用,不能new </script> </head> <body> </body> </html>