cody-utils 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +9 -9
  2. package/dist/cody-utils.min.js +30 -30
  3. package/package.json +8 -2
  4. package/.history/package_20200212101131.json +0 -19
  5. package/.history/package_20250527165758.json +0 -19
  6. package/.history/package_20250527165800.json +0 -19
  7. package/.history/package_20250527165806.json +0 -19
  8. package/.history/package_20250527165810.json +0 -19
  9. package/.history/package_20250527165815.json +0 -19
  10. package/.history/package_20250527165817.json +0 -19
  11. package/.history/package_20250527165826.json +0 -19
  12. package/.history/package_20250527165829.json +0 -19
  13. package/.history/package_20250527165835.json +0 -19
  14. package/.history/package_20250527170050.json +0 -19
  15. package/.history/package_20250527170051.json +0 -19
  16. package/.history/webpack.config_20200212101131.js +0 -23
  17. package/.history/webpack.config_20250527165622.js +0 -23
  18. package/.history/webpack.config_20250527165631.js +0 -23
  19. package/.history/webpack.config_20250527165643.js +0 -23
  20. package/.history/webpack.config_20250527165647.js +0 -23
  21. package/test/01_call_apply_bind.html +0 -47
  22. package/test/02_throttle_debounce.html +0 -54
  23. package/test/02_/345/207/275/346/225/260/351/230/262/346/212/226/344/270/216/350/212/202/346/265/201.jpg +0 -0
  24. package/test/03_array_declare.html +0 -51
  25. package/test/04_array_unique.html +0 -32
  26. package/test/05_array_concat_slice.html +0 -28
  27. package/test/06_array_flatten.html +0 -23
  28. package/test/07_array_compact_chunk.html +0 -25
  29. package/test/08_array_difference_merge.html +0 -22
  30. package/test/09_array_pull_pullAll.html +0 -27
  31. package/test/10_array_drop_dropRight.html +0 -32
  32. package/test/11_new_instanceof.html +0 -47
  33. package/test/12_object_merge.html +0 -34
  34. package/test/13_deepClone.html +0 -42
  35. package/test/13_shallowClone.html +0 -27
  36. package/test/13_/346/265/213/350/257/225/351/201/215/345/216/206/345/257/271/350/261/241/346/225/210/347/216/207.html +0 -38
  37. package/test/13_/346/265/213/350/257/225/351/201/215/345/216/206/346/225/260/347/273/204/346/225/210/347/216/207.html +0 -60
  38. package/test/14_string.html +0 -21
  39. package/test/15_/346/211/213/345/206/231/347/273/247/346/211/277.html +0 -53
  40. package/test/16_/346/211/213/345/206/231/344/272/213/344/273/266/346/200/273/347/272/277.html +0 -32
  41. package/test/17_/346/211/213/345/206/231/346/266/210/346/201/257/350/256/242/351/230/205/344/270/216/345/217/221/345/270/203.html +0 -48
  42. package/test/18_/346/211/213/345/206/231Promise.html +0 -49
  43. package/test/19_/346/211/213/345/206/231ajax/350/257/267/346/261/202/345/207/275/346/225/260.html +0 -102
  44. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/01_/345/237/272/346/234/254/346/225/260/346/215/256/347/273/223/346/236/204_/346/225/260/347/273/204//346/225/260/347/273/204/345/270/270/350/247/201/346/223/215/344/275/2341.html +0 -48
  45. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/01_/345/237/272/346/234/254/346/225/260/346/215/256/347/273/223/346/236/204_/346/225/260/347/273/204//346/225/260/347/273/204/345/270/270/350/247/201/346/223/215/344/275/2342.html +0 -74
  46. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/01_/345/237/272/346/234/254/346/225/260/346/215/256/347/273/223/346/236/204_/346/225/260/347/273/204//346/225/260/347/273/204/345/270/270/350/247/201/346/223/215/344/275/2343.html +0 -53
  47. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/01_/345/237/272/346/234/254/346/225/260/346/215/256/347/273/223/346/236/204_/346/225/260/347/273/204//346/225/260/347/273/204/345/270/270/350/247/201/346/223/215/344/275/2344.html +0 -54
  48. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/02_/345/237/272/346/234/254/346/225/260/346/215/256/347/273/223/346/236/204_/346/240/210//346/240/210_/345/272/224/347/224/250_/345/215/201/350/277/233/345/210/266/350/275/254/344/272/214/350/277/233/345/210/266.html +0 -41
  49. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/02_/345/237/272/346/234/254/346/225/260/346/215/256/347/273/223/346/236/204_/346/240/210//346/240/210_/346/265/213/350/257/225.html +0 -29
  50. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/03_/345/237/272/346/234/254/346/225/260/346/215/256/347/273/223/346/236/204_/351/230/237/345/210/227//344/274/230/345/205/210/347/272/247/351/230/237/345/210/227_/346/265/213/350/257/225.html +0 -29
  51. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/03_/345/237/272/346/234/254/346/225/260/346/215/256/347/273/223/346/236/204_/351/230/237/345/210/227//351/230/237/345/210/227_/345/272/224/347/224/250_/345/207/273/351/274/223/344/274/240/350/212/261.html +0 -38
  52. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/03_/345/237/272/346/234/254/346/225/260/346/215/256/347/273/223/346/236/204_/351/230/237/345/210/227//351/230/237/345/210/227_/346/265/213/350/257/225.html +0 -33
  53. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/04_/346/225/260/346/215/256/347/273/223/346/236/204_/351/223/276/350/241/250//345/217/214/345/220/221/351/223/276/350/241/250_/346/265/213/350/257/225.html +0 -55
  54. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/04_/346/225/260/346/215/256/347/273/223/346/236/204_/351/223/276/350/241/250//351/223/276/350/241/250_/346/265/213/350/257/225.html +0 -52
  55. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/05_/346/225/260/346/215/256/347/273/223/346/236/204_/346/240/221//344/272/214/345/217/211/346/220/234/347/264/242/346/240/221_/346/265/213/350/257/225.html +0 -48
  56. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/06_/346/225/260/346/215/256/347/273/223/346/236/204_/351/233/206/345/220/210//351/233/206/345/220/210_/346/265/213/350/257/225.html +0 -50
  57. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/07_/346/216/222/345/272/217/347/256/227/346/263/225/3/347/247/215/345/237/272/346/234/254/346/216/222/345/272/217_/346/265/213/350/257/225.html +0 -19
  58. package/test/20_/346/225/260/346/215/256/347/273/223/346/236/204/344/270/216/347/256/227/346/263/225/07_/346/216/222/345/272/217/347/256/227/346/263/225//351/253/230/347/272/247/346/216/222/345/272/217_/346/265/213/350/257/225.html +0 -19
  59. package/test/README.md +0 -207
  60. package/test/db.json +0 -54
  61. package/webpack.config.js +0 -23
  62. package//350/207/252/345/256/232/344/271/211npm/345/267/245/345/205/267/345/272/223.md +0 -91
@@ -1,47 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>自定义new与instanceof工具函数</title>
7
- </head>
8
- <body>
9
- <script>
10
- /*
11
- 1. 自定义new工具函数
12
- 语法: newInstance(Fn, ...args)
13
- 功能: 创建Fn构造函数的实例对象
14
- 实现: 创建空对象obj, 调用Fn指定this为obj, 返回obj
15
- 2. 自定义instanceof工具函数
16
- 语法: myInstanceOf(obj, Type)
17
- 功能: 判断obj是否是Type类型的实例
18
- 实现: Type的原型对象是否是obj的原型链上的某个对象, 如果是返回tru, 否则返回false
19
- */
20
- </script>
21
- <script src="../dist/atguigu-utils.js"></script>
22
- <script>
23
- function Person(name, age) {
24
- this.name = name
25
- this.age = age
26
- return {}
27
- // return []
28
- // return function (){}
29
- // return 1
30
- // return undefined
31
- }
32
-
33
- const p = new Person('tom', 12)
34
- console.log(p)
35
-
36
- const p2 = aUtils.newInstance(Person, 'Jack', 13)
37
- console.log(p2, p2.constructor)
38
-
39
- </script>
40
- <script>
41
- console.log(aUtils.myInstanceOf(p, Object))
42
- console.log(aUtils.myInstanceOf(p, Person))
43
- console.log(aUtils.myInstanceOf(aUtils.myInstanceOf, Function))
44
- console.log(aUtils.myInstanceOf(p, String), aUtils.myInstanceOf(p, Function))
45
- </script>
46
- </body>
47
- </html>
@@ -1,34 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
- <title>合并多个对象</title>
8
- </head>
9
- <body>
10
- <!--
11
- 语法: object mergeObject(...objs)
12
- 功能: 合并多个对象, 返回一个合并后对象(不改变原对象)
13
- 合并前:
14
- { a: [{ x: 2 }, { y: 4 }], b: 1}
15
- { a: { z: 3}, b: [2, 3], c: 'foo'}
16
- 合并后:
17
- { a: [ { x: 2 }, { y: 4 }, { z: 3 } ], b: [ 1, 2, 3 ], c: 'foo' }
18
- -->
19
- <script src="../dist/atguigu-utils.js"></script>
20
- <script>
21
- const object = {
22
- a: [{ x: 2 }, { y: 4 }],
23
- b: 1
24
- }
25
- const other = {
26
- a: { z: 3},
27
- b: [2, 3],
28
- c: 'foo'
29
- }
30
- console.log(aUtils.mergeObject(object, other))
31
- // { a: [ { x: 2 }, { y: 4 }, { z: 3 } ], b: [ 1, 2, 3 ], c: 'foo' }
32
- </script>
33
- </body>
34
- </html>
@@ -1,42 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>深度克隆/深复制/深拷贝</title>
7
- </head>
8
- <body>
9
- <script src="https://cdn.bootcss.com/lodash.js/4.17.15/lodash.min.js"></script>
10
- <!--
11
- 实现深拷贝
12
- 1). 大众乞丐版
13
- 问题1: 函数属性会丢失
14
- 问题2: 循环引用会出错
15
- 2). 面试基础版本
16
- 解决问题1: 函数属性还没丢失
17
- 3). 面试加强版本
18
- 解决问题2: 循环引用正常
19
- 4). 面试加强版本2(优化遍历性能)
20
- 数组: while | for | forEach() 优于 for-in | keys()&forEach()
21
- 对象: for-in 与 keys()&forEach() 差不多
22
- -->
23
- <script src="../dist/atguigu-utils.js"></script>
24
- <script>
25
- const obj1 = {
26
- a: 1,
27
- b: [ 'e', 'f', 'g'],
28
- c: { h: { i: 2 } },
29
- d: function (){}
30
- }
31
- obj1.b.push(obj1.c)
32
- obj1.c.j = obj1.b
33
-
34
- // const obj1Clone = _.cloneDeep(obj1)
35
- // const obj1Clone = aUtils.deepClone1(obj1)
36
- // const obj1Clone = aUtils.deepClone2(obj1)
37
- // const obj1Clone = aUtils.deepClone3(obj1)
38
- const obj1Clone = aUtils.deepClone4(obj1)
39
- console.log(obj1Clone, obj1Clone.c === obj1.c, obj1Clone.d===obj1.d)
40
- </script>
41
- </body>
42
- </html>
@@ -1,27 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>浅克隆/浅复制/浅拷贝</title>
7
- </head>
8
- <body>
9
- <!--
10
- 实现浅拷贝
11
- 方法一: 利用ES6语法
12
- 方法二: 利用ES5语法: for...in
13
- -->
14
- <script src="../dist/atguigu-utils.js"></script>
15
- <script>
16
- const obj1 = { x: 'abc', y: {m: 1} }
17
- // const obj2 = aUtils.clone1(obj1)
18
- const obj2 = aUtils.clone2(obj1)
19
- console.log(obj2, obj2===obj1, obj2.x===obj1.x, obj2.y===obj1.y)
20
-
21
- const arr1 = ['abc', {m: 1}]
22
- // const arr2 = aUtils.clone1(arr1)
23
- const arr2 = aUtils.clone2(arr1)
24
- console.log(arr2, arr2===arr1, arr2[0]===arr1[0], arr2[1]===arr1[1])
25
- </script>
26
- </body>
27
- </html>
@@ -1,38 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>测试各种遍历对象的效率</title>
7
- </head>
8
- <body>
9
- <script>
10
- /*
11
- 测试: for...in / keys & forEach
12
- 耗时: 差不多
13
- */
14
- const obj = new Object();
15
- for (let i = 0; i < 100000; i++) {
16
- obj[i] = 1
17
- }
18
-
19
- // for..in
20
- console.time()
21
- for (const key in obj) {
22
- if (obj.hasOwnProperty(key)) {
23
- // const element = obj[key];
24
- }
25
- }
26
- console.timeEnd()
27
-
28
-
29
- // keys() + forEach
30
- console.time()
31
- Object.keys(obj).forEach(key => {
32
- // let element32 = obj[key]
33
- })
34
- console.timeEnd()
35
-
36
- </script>
37
- </body>
38
- </html>
@@ -1,60 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>测试各种遍历数组的效率</title>
7
- </head>
8
- <body>
9
- <script>
10
- /*
11
- 测试: for...in / for / forEach / keys&forEach / while
12
- 耗时: for...in | keys&forEach > for | forEach | while
13
- */
14
- const arr = new Array();
15
- for (let i = 0; i < 100000; i++) {
16
- arr.push(1)
17
- }
18
-
19
- // for..in
20
- console.time()
21
- for (const key in arr) {
22
- let element = arr[key];
23
- }
24
- console.timeEnd()
25
-
26
- //for
27
- console.time()
28
- for (let index = 0; index < arr.length; index++) {
29
- let element2 = arr[index];
30
- }
31
- console.timeEnd()
32
-
33
- // forEach
34
- console.time()
35
- arr.forEach(item => {
36
- let element3 = item;
37
- })
38
- console.timeEnd()
39
-
40
- // keys() + forEach
41
- console.time()
42
- Object.keys(arr).forEach(index => {
43
- let element32 = arr[index]
44
- })
45
- console.timeEnd()
46
-
47
-
48
-
49
- // while
50
- console.time()
51
- const length = arr.length
52
- let index = 0
53
- while(index++ < length) {
54
- let element4 = arr[index]
55
- }
56
- console.timeEnd()
57
-
58
- </script>
59
- </body>
60
- </html>
@@ -1,21 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>字符串处理的系列方法</title>
7
- </head>
8
- <body>
9
- <!--
10
- 1. 字符串倒序: reverseString(str) 生成一个倒序的字符串
11
- 2. 字符串是否是回文: palindrome(str) 如果给定的字符串是回文,则返回 true ;否则返回 false
12
- 3. 截取字符串: truncate(str, num) 如果字符串的长度超过了num, 截取前面num长度部分, 并以...结束
13
- -->
14
- <script src="../dist/atguigu-utils.js"></script>
15
- <script>
16
- console.log(aUtils.reverseString('abcd')) // dcba
17
- console.log(aUtils.palindrome('abcb'), aUtils.palindrome('abcba')) // false true
18
- console.log(aUtils.truncate('boomerang', 7)) // boomera...
19
- </script>
20
- </body>
21
- </html>
@@ -1,53 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>手写继承</title>
8
- </head>
9
-
10
- <body>
11
- <!--
12
- 手写继承:
13
- 实现方式: 寄生组合式
14
- 说明: 其它方式的继承会在一次实例中调用两次父类的构造函数或有其它缺点
15
- -->
16
- <script>
17
- function Parent(name, age) {
18
- this.name = name
19
- this.age = age
20
- }
21
- Parent.prototype.sayName = function () {
22
- console.log('name:', this.name)
23
- }
24
-
25
- function Child(name, age, score) {
26
- Parent.call(this, name, age)
27
- this.score = score
28
- }
29
-
30
- function create(proto) {
31
- function F() {}
32
- F.prototype = proto
33
- return new F()
34
- }
35
-
36
- Child.prototype = create(Parent.prototype)
37
- Child.prototype.constructor = Child
38
- Child.prototype.sayScore = function () {
39
- console.log('score:', this.score)
40
- }
41
-
42
- // 创建父类型对象
43
- var parent = new Parent('father', 30)
44
- parent.sayName()
45
-
46
- // 创建子类型对象
47
- var child = new Child('son', 5, 90)
48
- child.sayName()
49
- child.sayScore()
50
- </script>
51
- </body>
52
-
53
- </html>
@@ -1,32 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
- <title>手写事件总线</title>
8
- </head>
9
- <body>
10
-
11
- <script src="../dist/atguigu-utils.js"></script>
12
- <script>
13
- const { eventBus } = aUtils
14
- eventBus.on('add', (data) => {
15
- console.log('add', data)
16
- })
17
- eventBus.on('add', (data) => {
18
- console.log('add2', data)
19
- })
20
- eventBus.on('delete', (data) => {
21
- console.log('delete', data)
22
- })
23
-
24
- // eventBus.off('add')
25
- // eventBus.off()
26
-
27
- eventBus.emit('add', 123)
28
- eventBus.emit('delete', 'abc')
29
-
30
- </script>
31
- </body>
32
- </html>
@@ -1,48 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
- <title>Document</title>
8
- </head>
9
- <body>
10
-
11
- <!--
12
- PubSub 包含n个方法的对象
13
- 1. subcribe(msgName, callback): 订阅消息
14
- 2. publish(msgName, data): 发布异步的消息
15
- 3. publishSync(msgName, data): 发布同步的消息
16
- 4. unsubscribe(flag): 取消消息订阅
17
- -->
18
- <script src="../dist/atguigu-utils.js"></script>
19
- <script>
20
- const { PubSub } = aUtils
21
- // 订阅消息
22
- PubSub.subscribe('add', (data) => {
23
- console.log('add()...', data)
24
- })
25
- PubSub.subscribe('add', (data) => {
26
- console.log('add2()...', data)
27
- })
28
- const token = PubSub.subscribe('add', (data) => {
29
- console.log('add3()...', data)
30
- })
31
- PubSub.subscribe('update', (data) => {
32
- console.log('update()...', data)
33
- })
34
-
35
- // PubSub.unsubscribe(token)
36
- // PubSub.unsubscribe('add')
37
- // PubSub.unsubscribe()
38
-
39
- PubSub.publish('add', 12)
40
- PubSub.publish('update', 13)
41
- console.log('----')
42
- // PubSub.unsubscribe(token)
43
- // PubSub.unsubscribe('add')
44
-
45
- </script>
46
-
47
- </body>
48
- </html>
@@ -1,49 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
- <title>手写Promise</title>
8
- </head>
9
- <body>
10
-
11
- <script src="../dist/atguigu-utils.js"></script>
12
- <script>
13
- const { Promise } = aUtils
14
- new Promise((resolve, reject) => {
15
- // resolve(1)
16
- // setTimeout(() => {
17
- reject(2)
18
- // }, 1000);
19
- })
20
- .then(value => {
21
- console.log('onResolve()1')
22
- })
23
- .then(
24
- value => {console.log('onResolved()2', value)},
25
- reason => {
26
- console.log('onRejected2()', reason)
27
- // return 3
28
- // throw 4
29
- // return new Promise((resolve, reject) =>resolve(5))
30
- return new Promise((resolve, reject) =>reject(6))
31
- }
32
- ).then(
33
- value => {console.log('onResolved3()', value)},
34
- reason => {
35
- console.log('onRejected3()', reason)
36
- // throw reason
37
- }
38
- ).catch(reason => {
39
- console.log('onRejected4()', reason)
40
- }).then(
41
- value => {console.log('onResolved5()', value)},
42
- reason => {
43
- console.log('onRejected5()', reason)
44
- }
45
- )
46
- </script>
47
-
48
- </body>
49
- </html>
@@ -1,102 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
- <title>手写ajax请求函数</title>
8
- </head>
9
- <body>
10
- <button onclick="testGet()">发送GET请求</button><br>
11
- <button onclick="testPost()">发送POST请求</button><br>
12
- <button onclick="testPut()">发送PUT请求</button><br>
13
- <button onclick="testDelete()">发送Delete请求</button><br>
14
-
15
- <script src="../dist/atguigu-utils.js"></script>
16
- <script>
17
- const { axios } = aUtils
18
-
19
- /* 1. GET请求: 从服务器端获取数据*/
20
- function testGet() {
21
- axios({
22
- // url: 'http://localhost:3000/posts',
23
- url: 'http://localhost:3000/posts2',
24
- method: 'GET',
25
- params: {
26
- id: 1,
27
- xxx: 'abc'
28
- }
29
- })
30
- // axios.get('http://localhost:3000/posts', {params: {id: 1}})
31
- .then(
32
- response => {
33
- console.log(response)
34
- },
35
- error => {
36
- alert(error.message)
37
- }
38
- )
39
- }
40
-
41
- /* 2. POST请求: 服务器端保存数据*/
42
- function testPost() {
43
- axios({
44
- url: 'http://localhost:3000/posts',
45
- method: 'POST',
46
- data: {
47
- "title": "json-server---",
48
- "author": "typicode---"
49
- }
50
- })
51
- // axios.post('http://localhost:3000/posts', {title: 'aaa', author: 'bbb'})
52
- .then(
53
- response => {
54
- console.log(response)
55
- },
56
- error => {
57
- alert(error.message)
58
- }
59
- )
60
- }
61
-
62
- /* 3. PUT请求: 服务器端更新数据*/
63
- function testPut() {
64
- axios({
65
- url: 'http://localhost:3000/posts/1',
66
- method: 'put',
67
- data: {
68
- "title": "json-server+++",
69
- "author": "typicode+++"
70
- }
71
- })
72
- // axios.put('http://localhost:3000/posts/1', {title: 'aaa222', author: 'bbb222'})
73
- .then(
74
- response => {
75
- console.log(response)
76
- },
77
- error => {
78
- alert(error.message)
79
- }
80
- )
81
- }
82
-
83
- /* 2. DELETE请求: 服务器端删除数据*/
84
- function testDelete() {
85
- axios({
86
- url: 'http://localhost:3000/posts/2',
87
- method: 'delete'
88
- })
89
- // axios.delete('http://localhost:3000/posts/2')
90
- .then(
91
- response => {
92
- console.log(response)
93
- },
94
- error => {
95
- alert(error.message)
96
- }
97
- )
98
- }
99
- </script>
100
-
101
- </body>
102
- </html>
@@ -1,48 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
- <title>Document</title>
8
- </head>
9
- <body>
10
-
11
- <script>
12
- /*
13
- 1. 理解
14
- 多个有序数元素的列表
15
- 每个元素都有一个唯一的数值标号, 且从0开始依次递增
16
- 在内存中数据是保存在一块连续的内存中的
17
- 2. 相关API操作
18
- 静态方法
19
- 更新的方法
20
- 遍历相关的声明式方法
21
- 其它方法
22
- */
23
-
24
- /*
25
- 静态方法
26
- from(): 从一个类似数组或可迭代对象创建一个新的,浅拷贝的数组实例
27
- of(): 创建一个具有可变数量参数的新数组实例
28
- isArray()
29
- */
30
-
31
- // from(): 从一个类似数组或可迭代对象创建一个新的,浅拷贝的数组实例
32
- function f() {
33
- return Array.from(arguments);
34
- }
35
- console.log(f(1, 2, 3));
36
- const set = new Set(['foo', 'bar', 'baz', 'foo']);
37
- console.log(Array.from(set));
38
-
39
- // of(): 创建一个具有可变数量参数的新数组实例
40
- console.log(Array.of(3)); // [3]
41
- console.log(Array.of(1, 2, 3)); // [1, 2, 3]
42
-
43
- // isArray()
44
- console.log(Array.isArray([1, 2, 3]), Array.isArray({foo: 123}));
45
-
46
- </script>
47
- </body>
48
- </html>
@@ -1,74 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
- <title>Document</title>
8
- </head>
9
- <body>
10
-
11
- <script>
12
- /*
13
- 1. 理解
14
- 多个有序数元素的列表
15
- 每个元素都有一个唯一的数值标号, 且从0开始依次递增
16
- 在内存中数据是保存在一块连续的内存中的
17
- 2. 相关API操作
18
- 静态方法
19
- 更新的方法
20
- 遍历相关的声明式方法
21
- 其它方法
22
- */
23
-
24
- /*
25
- 更新的方法
26
- push()
27
- pop()
28
- unshift()
29
- shift()
30
- sort()
31
- reverse()
32
- splice()
33
- */
34
-
35
- /*
36
- 需求:
37
- 1. 在数组的最后添加6
38
- 2. 在数组的最后一次添加8和9
39
- 3. 在数组的最后添加包含8和9的数组
40
- 4. 删除数组的最后一个元素
41
- 5. 在数组的最前面添加2
42
- 6. 在数组的最前面一次添加4和3(注: 3在前, 4在后)
43
- 7. 删除数组的第一个元素
44
- 8. 对数组进行按数值降序排列
45
- 9. 对数组进行倒序排列
46
- 10. 删除第3个元素
47
- 11. 将第3个元素替换为10(不能直接赋值)
48
- 12. 将11插入为数组的第3个元素
49
- */
50
-
51
- const arr = [3, 1, 14, 9, 7, 6]
52
-
53
- arr.push(6)
54
- arr.push(8, 9) // 添加2个元素
55
- arr.push([8, 9]) // 添加1个元素
56
- console.log(arr.pop())
57
-
58
- arr.unshift(2)
59
- arr.unshift(3, 4)
60
- console.log(arr.shift())
61
-
62
- arr.sort()
63
- arr.sort((item1, item2) => item2 - item1) // 根据数值降序
64
-
65
- arr.reverse()
66
-
67
- arr.splice(2, 1)
68
- arr.splice(2, 1, 4)
69
- arr.splice(2, 0, 3)
70
-
71
- console.log(arr)
72
- </script>
73
- </body>
74
- </html>