Skip to content

Commit 8410ff5

Browse files
es
1 parent ca8cb5b commit 8410ff5

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

01-JS语言基础/数据格式处理/01-正则表达式.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
// g 全局模式(global)(全文查找出现的所有pattern)
8181
// i 不区分大小写(ease-insensitive)(忽略大小写)
8282
// m 执行多行匹配
83-
83+
// y (es6) 相当于 ^$,保证每次匹配是连续的
8484
// u (es6) Unicode模式,正确处理大于\uFFFF的Unicode字符(四个字节的 UTF-16 编码)
8585
var s = '𠮷';
8686
/^.$/.test(s); // false

01-JS语言基础/数据类型与转换/Array.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
var arr3 = new Array(1,2,3);
2727

2828
// 【概念】:浅拷贝、深拷贝
29-
// 浅拷贝,复制的是引用
29+
// 浅拷贝,复制的是引用 Object.assign
3030
// 深拷贝,遍历数组赋值,复制的是值
31-
// TODO
3231

3332
// 在javascript中数组长度可变
3433
var arr = new Array(3); // 创建了一个长度为3的数组对象。

01-JS语言基础/数据类型与转换/arguments.html

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
<!--
2+
* @Author: victorsun - csxiaoyao
3+
* @Date: 2019-01-12 16:25:43
4+
* @LastEditors : victorsun
5+
* @LastEditTime : 2020-02-02 18:23:07
6+
* @Description: www.csxiaoyao.com
7+
-->
18
<!DOCTYPE html>
29
<html lang="en">
310
<head>
@@ -7,17 +14,6 @@
714
//函数内部的一个对象 arguments
815
//当函数调用的时候,系统会将所有传入的实参,依次存入这个数组对象
916

10-
//【要求】允许函数调用时传入任意个数参数,并且函数返回这些数字中最大的数字
11-
function max(){
12-
// console.log(arguments);
13-
var maxNum = arguments[0];
14-
for (var i = 1; i < arguments.length; i++) {
15-
maxNum = maxNum > arguments[i] ? maxNum :arguments[i];
16-
}
17-
return maxNum;
18-
}
19-
console.log(max(1, 2, 34, 5, 6));//34
20-
2117
//【要求】数组去重
2218
var distinct = new Function(`
2319
var arr = [];
@@ -30,6 +26,31 @@
3026
`);
3127
console.log(distinct(1, 2, 34, 34, 5, 5));//[1, 2, 34, 5]
3228

29+
/**
30+
* 默认参数表达式 & 参数长度
31+
*/
32+
function f (x, y = 7, z = x + y) { // 默认参数表达式
33+
console.log(arguments.length) // 4 传入的参数个数,和形参无关
34+
console.log(f.length) // 1 第一个带默认参数前的参数个数
35+
return x * 10 + z
36+
}
37+
console.log(f(1, undefined, 3, 4)) // 13
38+
39+
/**
40+
* 参数遍历
41+
*/
42+
function sum () {
43+
let num = 0
44+
Array.prototype.forEach.call(arguments, function (item) {
45+
num += item * 2
46+
})
47+
Array.from(arguments).forEach(function (item) {
48+
num += item * 2
49+
})
50+
return num
51+
}
52+
console.log(sum(1,2,3)) // 24
53+
3354
</script>
3455
</head>
3556
<body>

02-ES新特性/ES6/04-Map&Set.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
/**
1212
* 【 Map 对象 】
1313
* 保存键值对,任何值(对象或原始值)都可以作为键或值
14+
* 初始值必须为kv形式:[[k1,v1],[k2,v2]]
15+
* [ set / delete / clear / size / get / keys / values / entires ]
16+
* for (let [key, value] of map) {}
17+
* Object.assign(target, source) // 复制
1418
*/
1519
// Maps 和 Objects 区别:
1620
// 1. 键的类型:Object只能是字符串或Symbols,Map可以是任意值
@@ -96,6 +100,9 @@
96100
/**
97101
* 【 Set 对象 】
98102
* 存储任何类型的唯一值,无论是原始值或是对象引用
103+
* 初始化的值为可遍历对象即可
104+
* [ add / delete / clear / size / has / keys|values / entries ]
105+
* forEach / for...of
99106
*/
100107
/**
101108
* Set 中的特殊值
@@ -114,6 +121,7 @@
114121

115122
/**
116123
* Set 类型转换
124+
* 可遍历对象即可
117125
*/
118126
// Array => Set
119127
var mySet2 = new Set(["value1", "value2", "value3"]);
@@ -130,14 +138,14 @@
130138
var mySet4 = new Set([1, 2, 3, 4, 4]);
131139
[...mySet4]; // [1, 2, 3, 4]
132140

133-
// 【 集合 】
141+
// 2.【 集合 】运算
134142
var a = new Set([1, 2, 3]);
135143
var b = new Set([4, 3, 2]);
136-
// 2. 并集
144+
// 并集
137145
var union = new Set([...a, ...b]); // Set(4) {1, 2, 3, 4}
138-
// 3. 交集
146+
// 交集
139147
var intersect = new Set([...a].filter(x => b.has(x))); // Set(2) {2, 3}
140-
// 4. 差集
148+
// 差集
141149
var difference = new Set([...a].filter(x => !b.has(x))); // Set(1) {1}
142150

143151
</script>

0 commit comments

Comments
 (0)