Skip to content

Commit 8e032da

Browse files
committed
5.函数-参数
1 parent 605326a commit 8e032da

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

5.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function show(a, b, ...args) {
2+
console.log(a)
3+
console.log(b)
4+
console.log(args)
5+
}
6+
console.log(show(1, 2, 3, 4, 5))
7+
8+
let arr1 = [1, 2, 3]
9+
let arr2 = [4, 5, 6]
10+
let arr3 = [...arr1, ...arr2]
11+
console.log(arr3)
12+
13+
function show2(a, b=5, c=8) {
14+
console.log(a, b, c)
15+
}
16+
show2(88, 12)

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ES6 各种新语法 入门了解 石川blue讲解
1717
- [2.ES6兼容性](#2es6%E5%85%BC%E5%AE%B9%E6%80%A7)
1818
- [3.变量 let 和 常量 const](#3%E5%8F%98%E9%87%8F-let-%E5%92%8C-%E5%B8%B8%E9%87%8F-const)
1919
- [4.函数-箭头函数](#4%E5%87%BD%E6%95%B0-%E7%AE%AD%E5%A4%B4%E5%87%BD%E6%95%B0)
20+
- [5.函数-参数](#5%E5%87%BD%E6%95%B0-%E5%8F%82%E6%95%B0)
2021

2122
----
2223

@@ -147,3 +148,28 @@ console.log(show4(10))
147148
console.log(show5(10))
148149
```
149150

151+
## 5.函数-参数
152+
153+
- 参数扩展/展开 `...args`
154+
- 收集剩余的参数,必须当到最后一个参数位置
155+
- 展开数组,简写,效果和直接把数组的内容写在这儿一样
156+
- 默认参数
157+
158+
```js
159+
function show(a, b, ...args) {
160+
console.log(a)
161+
console.log(b)
162+
console.log(args)
163+
}
164+
console.log(show(1, 2, 3, 4, 5))
165+
166+
let arr1 = [1, 2, 3]
167+
let arr2 = [4, 5, 6]
168+
let arr3 = [...arr1, ...arr2]
169+
console.log(arr3)
170+
171+
function show2(a, b=5, c=8) {
172+
console.log(a, b, c)
173+
}
174+
show2(88, 12)
175+
```

0 commit comments

Comments
 (0)