Rest 参数和 spread 扩展运算符
Rest 参数与 spread 扩展运算符在 ES6 中已经引入,不过 ES6 中只针对于数组,在 ES9 中为对象提供了像数组一样的 rest 参数和扩展运算符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ES9 Rest 参数和 spread 扩展运算符</title> </head>
<body>
<script> function connectionConfig({ip, port, ...info}) { console.log(ip); console.log(port); console.log(info); console.log(info.type); }
connectionConfig({ ip: "127.0.0.1", port: 3306, username: "root", password: "123456", type: "jdbc" });
const host = { ip: "127.0.0.1", port: 3306 }; const user = { username: "root", password: "123456" }; const database = { type: "jdbc" };
const dbConnectionInfo = {...host, ...user, ...database}; console.log(dbConnectionInfo);
</script>
</body>
</html>
|