@@ -105,8 +105,8 @@ var func = (a, b) => {
105
105
106
106
** 顶部变量属性** : ` var ` 声明的变量会挂载在 window 上,而 ` let ` 和 ` const ` 声明的变量不会
107
107
** 变量提升** : ` var ` 变量可在声明之前使用,` let ` 和 ` const ` 不可以
108
- ** 暂时性死区** :` var ` 不存在暂时性死区,在代码块中,用 ` let ` 或 ` const ` 声明变量之前,使用会抛出异常 (暂时性死区)
109
- ** 重复声明** : ` var ` 允许重复声明,` let ` 和 ` const ` 命令声明的变量不允许重复声明
108
+ ** 暂时性死区** :` var ` 不存在暂时性死区,在代码块中,用 ` let ` 或 ` const ` 声明变量之前,使用会抛出异常 (暂时性死区)
109
+ ** 重复声明** : ` var ` 允许重复声明,` let ` 和 ` const ` 命令声明的变量不允许重复声明
110
110
** 初始值** : ` var ` 和 ` let ` 可以没有初始值,由于 ` const ` 声明的是只读的常量,一旦声明,就必须立即初始化,声明之后值不能改变
111
111
** 作用域** : ` var ` 没有块级作用域,` let ` 和 ` const ` 有块级作用域
112
112
@@ -121,7 +121,6 @@ var a = 2
121
121
122
122
console .log (b) // 报错,Uncaught ReferenceError: b is not defined
123
123
let b = 1
124
-
125
124
```
126
125
127
126
</p >
@@ -135,7 +134,7 @@ let b = 1
135
134
<p >
136
135
137
136
- ` forEach ` ` for ` 循环的简化,不能中断,没有 ` break/continue ` 方法,没有返回值。
138
- - ` map ` 只能遍历数组,不能中断,返回值是修改后的数组。
137
+ - ` map ` 只能遍历数组,不能中断,返回值是修改后的数组。
139
138
140
139
``` javascript
141
140
const arr = [1 , 2 , 3 , 4 , 5 ]
@@ -168,12 +167,11 @@ for...in 循环出的是 key,for...of 循环出的是 value
168
167
</details >
169
168
170
169
---
170
+
171
171
#### ES5,ES6 如何查找一个元素?
172
172
173
173
<details ><summary ><b >答案</b ></summary >
174
174
<p >
175
-
176
-
177
175
178
176
</p >
179
177
</details >
@@ -233,6 +231,99 @@ fn(1, 2, 3)
233
231
234
232
---
235
233
234
+ #### JS 怎么实现一个类,怎么实例化这个类?
235
+
236
+ <details ><summary ><b >答案</b ></summary >
237
+ <p >
238
+
239
+ Javascript 传统方法是通过构造函数定义并生成新对象。
240
+
241
+ ``` javascript
242
+ function Animal (type ) {
243
+ this .type = type
244
+ }
245
+ Animal .prototype .eat = function () {
246
+ console .log (' eat' )
247
+ }
248
+ var dog = new Animal (' dog' )
249
+ ```
250
+
251
+ ES6 引入了 ` CLASS ` 概念,` constructor ` 方法就是构造函数,定义 ` 类 ` 的方法时,前面不需要加 ` function ` 保留字,方法之前不需要逗号。
252
+
253
+ ``` javascript
254
+ class Animal {
255
+ constructor (type ) {
256
+ this .type = type
257
+ }
258
+ eat () {
259
+ console .log (' eat' )
260
+ }
261
+ }
262
+ var cat = new Animal (' cat' )
263
+ ```
264
+
265
+ </p >
266
+ </details >
267
+
268
+ ---
269
+
270
+ #### JS 怎么继承类?
271
+
272
+ <details ><summary ><b >答案</b ></summary >
273
+ <p >
274
+
275
+ ``` javascript
276
+ // 只实现了部分继承 ,prototype上的没有被继承
277
+ function Animal (type ) {
278
+ this .type = type
279
+ }
280
+ function Dog () {
281
+ Animal .call (this )
282
+ }
283
+
284
+ // ES6 实现继承
285
+ class Animal {
286
+ construtor (type ) {
287
+ this .type = type
288
+ }
289
+ eat () {
290
+ console .log (' eat' )
291
+ }
292
+ }
293
+ class Dog extends Animal {
294
+ construtor (type ) {
295
+ supper (type)
296
+ }
297
+ }
298
+ ```
299
+
300
+ </p >
301
+ </details >
302
+
303
+ ---
304
+
305
+ #### ES6 ` Set() ` ` Map() ` 添加值得方法?
306
+
307
+ <details ><summary ><b >答案</b ></summary >
308
+ <p >
309
+
310
+ 添加值方法: ` Set ` 使用` add ` 添加,` Map ` 使用` set ` 添加
311
+
312
+ ``` javascript
313
+ // Set
314
+ let mySet = new Set ()
315
+ mySet .add (1 )
316
+ // Map
317
+ const myMap = new Map ()
318
+ const o = { p: ' hello' }
319
+ myMap .set (o, ' world' )
320
+ ```
321
+
322
+ </p >
323
+ </details >
324
+
325
+ ---
326
+
236
327
#### es6 class static 解释?如何继承 static?
237
328
238
329
<details ><summary ><b >答案</b ></summary >
@@ -264,6 +355,74 @@ Bar.classMethod() // 'hello'
264
355
265
356
---
266
357
358
+ #### 什么闭包,闭包有什么用?
359
+
360
+ <details ><summary ><b >答案:star:</b ></summary >
361
+ <p >
362
+
363
+ </p >
364
+ </details >
365
+
366
+ ---
367
+
368
+ #### JS 如何获取函数所有参数?
369
+
370
+ 知识点:` rest参数 ` ` 类数组 `
371
+
372
+ <details ><summary ><b >答案</b ></summary >
373
+ <p >
374
+
375
+ ``` javascript
376
+ // ES5
377
+ function sum () {
378
+ console .log (arguments )
379
+ }
380
+ // ES6
381
+ function sum (... rest ) {
382
+ // rest 是数组
383
+ console .log (rest)
384
+ }
385
+ sum (1 , 2 , 3 )
386
+ ```
387
+
388
+ </p >
389
+ </details >
390
+
391
+ ---
392
+
393
+ #### 用箭头函数实现一个数组排序?
394
+
395
+ 知识点:` sort ` ` 箭头函数 `
396
+
397
+ <details ><summary ><b >答案</b ></summary >
398
+ <p >
399
+
400
+ ``` javascript
401
+ const arr = [10 , 5 , 40 , 25 , 1000 , 1 ]
402
+
403
+ arr .sort ((a , b ) => {
404
+ return a - b
405
+ })
406
+ console .log (arr) // [1, 5, 10, 25, 40, 1000]
407
+ ```
408
+
409
+ </p >
410
+ </details >
411
+
412
+ ---
413
+
414
+ #### 如何用箭头函数时间一个数组排序?
415
+
416
+ 知识点:` Object `
417
+
418
+ <details ><summary ><b >答案</b ></summary >
419
+ <p >
420
+
421
+ </p >
422
+ </details >
423
+
424
+ ---
425
+
267
426
#### 深拷贝和浅拷贝的区别,以及实现?
268
427
269
428
<details ><summary ><b >答案:star:</b ></summary >
@@ -331,6 +490,16 @@ console.log(obj) // {username: "sunnie"}
331
490
332
491
---
333
492
493
+ #### this?
494
+
495
+ <details ><summary ><b >答案</b ></summary >
496
+ <p >
497
+
498
+ </p >
499
+ </details >
500
+
501
+ ---
502
+
334
503
#### ` call ` 、` apply ` 、` bind ` 的区别,以及实现?
335
504
336
505
<details ><summary ><b >答案:star:</b ></summary >
@@ -431,7 +600,7 @@ function debounce(func, delay) {
431
600
432
601
** ` 函数节流 ` (throttle):节流顾名思义则是将减少一段时间内触发的频率。**
433
602
434
- 比如:我点击一个按钮,` delay ` 设置 3s ,我手速超快,从来不让点击间隔时间大于 3s 函数就不执行,一旦大于了 3s 就执行了
603
+ 比如:我点击一个按钮,` threshhold ` 设置 3s, 当我点第一次点击执行函数,接下来的 3s 内点都少次都没用,直到距离第一次 3s 执行第二次
435
604
436
605
``` javascript
437
606
function throttle (fn , threshhold = 3000 ) {
0 commit comments