Skip to content

Commit bc60ff5

Browse files
committed
javascript
1 parent c11318a commit bc60ff5

File tree

2 files changed

+108
-24
lines changed

2 files changed

+108
-24
lines changed

README.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,23 @@ var func = (a, b) => {
105105

106106
**顶部变量属性**`var` 声明的变量会挂载在 window 上,而 `let``const` 声明的变量不会
107107
**变量提升**`var` 变量可在声明之前使用,`let``const` 不可以
108-
**暂时性死区** `var`不存在暂时性死区,在代码块中,用 `let``const` 声明变量之前,该变量不可用
108+
**暂时性死区**`var`不存在暂时性死区,在代码块中,用 `let``const` 声明变量之前,使用会抛出异常 (暂时性死区)
109109
**重复声明**`var`允许重复声明,`let``const` 命令声明的变量不允许重复声明
110110
**初始值**`var``let`可以没有初始值,由于 `const` 声明的是只读的常量,一旦声明,就必须立即初始化,声明之后值不能改变
111111
**作用域**`var` 没有块级作用域,`let``const`有块级作用域
112112

113-
**修改 `const` 对象的某个属性会报错吗?**
113+
**拓展:修改 `const` 对象的某个属性会报错吗?**
114114
因为对象是引用类型的,`const`仅保证指针不发生改变,修改对象的属性不会改变对象的指针,所以是被允许的。
115115

116-
**小知识:输出什么?**
116+
**拓展:输出什么?**
117117

118118
```javascript
119-
console.log(a) //报错,Uncaught ReferenceError: a is not defined
120-
let a = 1
119+
console.log(a) // undefined
120+
var a = 2
121+
122+
console.log(b) //报错,Uncaught ReferenceError: b is not defined
123+
let b = 1
124+
121125
```
122126

123127
</p>
@@ -130,12 +134,13 @@ let a = 1
130134
<details><summary><b>答案</b></summary>
131135
<p>
132136

133-
- `forEach` `for`循环的简化,缺点是不能中断循环,没有`break/continue`方法。
134-
137+
- `forEach` `for`循环的简化,不能中断,没有 `break/continue` 方法,没有返回值。
138+
- `map` 只能遍历数组,不能中断,返回值是修改后的数组。
139+
135140
```javascript
136141
const arr = [1, 2, 3, 4, 5]
137142
for (let i = 0; i < arr.length; i++) {}
138-
// ES5 forEach
143+
// ES5 forEach
139144
arr.forEach(function(item) {})
140145
// ES5 every
141146
arr.every(function(item) {
@@ -154,20 +159,56 @@ for (let item of object) {
154159
console.log(key)
155160
}
156161
```
157-
**for...in迭代和for...of有什么区别**
158162

159-
for...in循环出的是key,for...of循环出的是value
163+
**拓展:for...in 迭代和 for...of 有什么区别**
164+
165+
for...in 循环出的是 key,for...of 循环出的是 value
166+
167+
</p>
168+
</details>
169+
170+
---
171+
#### ES5,ES6 如何查找一个元素?
172+
173+
<details><summary><b>答案</b></summary>
174+
<p>
175+
176+
160177

161178
</p>
162179
</details>
163180

164181
---
165182

166-
#### ES5中将伪数组转换成数组
183+
#### 什么是类数组(伪数组),如何转换成数组
167184

168185
<details><summary><b>答案</b></summary>
169186
<p>
170187

188+
`类数组(Array-Like Objects)` 是一个类似数组的对象,比如 `arguments` 对象,还有 `DOM API` 返回的 `NodeList` 对象都属于类数组对象。
189+
190+
类数组对象有下面两个特性:
191+
192+
- 具有:指向对象元素的数字索引下标和 `length` 属性
193+
- 不具有:比如 `push``shift``forEach` 以及 `indexOf` 等数组对象具有的方法
194+
195+
**类数组对象转数组方法:**
196+
197+
```javascript
198+
function fn() {
199+
// ES5 方法1:
200+
var arr = Array.prototype.slice.call(arguments)
201+
202+
// ES6 方法1:
203+
let arr = Array.from(arguments)
204+
// ES6 方法2:
205+
let arr = [...arguments]
206+
207+
// 以上三种请任选一种执行测试,为方便写在一起了
208+
arr.push(4) // arr -> [1, 2, 3, 4]
209+
}
210+
fn(1, 2, 3)
211+
```
171212

172213
</p>
173214
</details>
@@ -440,10 +481,11 @@ scroll 时触发操作,如随动效果:throttle
440481
<details><summary><b>答案</b></summary>
441482
<p>
442483

443-
&nbsp;&nbsp;&nbsp;&nbsp;扫描下方二维码:point_down::point_down:关注“前端女塾”
484+
&nbsp;&nbsp;&nbsp;&nbsp;扫描下方二维码:point_down::point_down:关注“前端女塾”
444485

445486
![logo](https://imgs.solui.cn/wx/640.gif ':size=262x224')
446487
关注公众号:回复“加群”即可加 前端仙女群
488+
447489
</p>
448490
</details>
449491

docs/javascript/README.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,23 @@ var func = (a, b) => {
105105

106106
**顶部变量属性**`var` 声明的变量会挂载在 window 上,而 `let``const` 声明的变量不会
107107
**变量提升**`var` 变量可在声明之前使用,`let``const` 不可以
108-
**暂时性死区** `var`不存在暂时性死区,在代码块中,用 `let``const` 声明变量之前,该变量不可用
108+
**暂时性死区**`var`不存在暂时性死区,在代码块中,用 `let``const` 声明变量之前,使用会抛出异常 (暂时性死区)
109109
**重复声明**`var`允许重复声明,`let``const` 命令声明的变量不允许重复声明
110110
**初始值**`var``let`可以没有初始值,由于 `const` 声明的是只读的常量,一旦声明,就必须立即初始化,声明之后值不能改变
111111
**作用域**`var` 没有块级作用域,`let``const`有块级作用域
112112

113-
**修改 `const` 对象的某个属性会报错吗?**
113+
**拓展:修改 `const` 对象的某个属性会报错吗?**
114114
因为对象是引用类型的,`const`仅保证指针不发生改变,修改对象的属性不会改变对象的指针,所以是被允许的。
115115

116-
**小知识:输出什么?**
116+
**拓展:输出什么?**
117117

118118
```javascript
119-
console.log(a) //报错,Uncaught ReferenceError: a is not defined
120-
let a = 1
119+
console.log(a) // undefined
120+
var a = 2
121+
122+
console.log(b) //报错,Uncaught ReferenceError: b is not defined
123+
let b = 1
124+
121125
```
122126

123127
</p>
@@ -130,12 +134,13 @@ let a = 1
130134
<details><summary><b>答案</b></summary>
131135
<p>
132136

133-
- `forEach` `for`循环的简化,缺点是不能中断循环,没有`break/continue`方法。
134-
137+
- `forEach` `for`循环的简化,不能中断,没有 `break/continue` 方法,没有返回值。
138+
- `map` 只能遍历数组,不能中断,返回值是修改后的数组。
139+
135140
```javascript
136141
const arr = [1, 2, 3, 4, 5]
137142
for (let i = 0; i < arr.length; i++) {}
138-
// ES5 forEach
143+
// ES5 forEach
139144
arr.forEach(function(item) {})
140145
// ES5 every
141146
arr.every(function(item) {
@@ -154,20 +159,56 @@ for (let item of object) {
154159
console.log(key)
155160
}
156161
```
157-
**for...in迭代和for...of有什么区别**
158162

159-
for...in循环出的是key,for...of循环出的是value
163+
**拓展:for...in 迭代和 for...of 有什么区别**
164+
165+
for...in 循环出的是 key,for...of 循环出的是 value
166+
167+
</p>
168+
</details>
169+
170+
---
171+
#### ES5,ES6 如何查找一个元素?
172+
173+
<details><summary><b>答案</b></summary>
174+
<p>
175+
176+
160177

161178
</p>
162179
</details>
163180

164181
---
165182

166-
#### ES5中将伪数组转换成数组
183+
#### 什么是类数组(伪数组),如何转换成数组
167184

168185
<details><summary><b>答案</b></summary>
169186
<p>
170187

188+
`类数组(Array-Like Objects)` 是一个类似数组的对象,比如 `arguments` 对象,还有 `DOM API` 返回的 `NodeList` 对象都属于类数组对象。
189+
190+
类数组对象有下面两个特性:
191+
192+
- 具有:指向对象元素的数字索引下标和 `length` 属性
193+
- 不具有:比如 `push``shift``forEach` 以及 `indexOf` 等数组对象具有的方法
194+
195+
**类数组对象转数组方法:**
196+
197+
```javascript
198+
function fn() {
199+
// ES5 方法1:
200+
var arr = Array.prototype.slice.call(arguments)
201+
202+
// ES6 方法1:
203+
let arr = Array.from(arguments)
204+
// ES6 方法2:
205+
let arr = [...arguments]
206+
207+
// 以上三种请任选一种执行测试,为方便写在一起了
208+
arr.push(4) // arr -> [1, 2, 3, 4]
209+
}
210+
fn(1, 2, 3)
211+
```
171212

172213
</p>
173214
</details>
@@ -440,10 +481,11 @@ scroll 时触发操作,如随动效果:throttle
440481
<details><summary><b>答案</b></summary>
441482
<p>
442483

443-
&nbsp;&nbsp;&nbsp;&nbsp;扫描下方二维码:point_down::point_down:关注“前端女塾”
484+
&nbsp;&nbsp;&nbsp;&nbsp;扫描下方二维码:point_down::point_down:关注“前端女塾”
444485

445486
![logo](https://imgs.solui.cn/wx/640.gif ':size=262x224')
446487
关注公众号:回复“加群”即可加 前端仙女群
488+
447489
</p>
448490
</details>
449491

0 commit comments

Comments
 (0)