Skip to content

Commit b68228c

Browse files
author
微信公众号:储凡
authored
Merge pull request #128 from 142vip/feat/es6-2016
feat(ES6): 新增2016新增特性和ts文档
2 parents f458ea9 + be7425f commit b68228c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2491
-835
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// 定义数组
2+
const students = ['Lisa', 'Tom']
3+
const keys = students.keys()
4+
5+
// 遍历keys对象
6+
let text = ''
7+
for (const x of keys) {
8+
text += x + '---'
9+
}
10+
console.log(text)

code/node/es6/es6-2015-map.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* 创建学生-年龄关系映射
3+
* - 存储键值对
4+
*/
5+
const studentAgeMap = new Map([
6+
['Tom', 20],
7+
['Lisa', 18]
8+
])
9+
10+
/**
11+
* 往集合中增加映射关系
12+
*/
13+
studentAgeMap.set('fairy', 24)
14+
15+
/**
16+
* 根据映射关键字获取值
17+
*/
18+
const age = studentAgeMap.get('fairy')
19+
20+
21+
/**
22+
* 返回集合中元素个数
23+
*/
24+
const size = studentAgeMap.size
25+
26+
27+
/**
28+
* 根据键删除映射关系
29+
*/
30+
studentAgeMap.delete('fairy')
31+
/**
32+
* 判断键是否存在
33+
*/
34+
studentAgeMap.has('fairy')
35+
36+
/**
37+
* 清空Map
38+
*/
39+
studentAgeMap.clear()
40+
41+
/**
42+
* 判断类型,返回对象object
43+
*/
44+
const mapType = typeof studentAgeMap
45+
46+
/**
47+
* 判断实例,返回true
48+
*/
49+
const isMap = studentAgeMap instanceof Map
50+
51+
/**
52+
* 循环处理
53+
*/
54+
studentAgeMap.forEach((value, key, originMap) => {
55+
console.log(key, value, JSON.stringify(originMap))
56+
})
57+
58+
/**
59+
* 获取所有的键
60+
*/
61+
studentAgeMap.keys()
62+
63+
/**
64+
* 获取所有的键、值
65+
*/
66+
studentAgeMap.entries()
67+
68+
69+
/**
70+
* 获取所有的值
71+
*/
72+
studentAgeMap.values()

code/node/es6/es6-2015-set.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 使用数组创建Set集合
3+
*/
4+
const stuSet = new Set([1, 2, 3])
5+
6+
/**
7+
* 利用add()方法创建Set集合
8+
*/
9+
const studentSet = new Set()
10+
studentSet.add(1)
11+
studentSet.add(2)
12+
studentSet.add(3)
13+
14+
/**
15+
* 列出集合中所有值
16+
*/
17+
let result = ''
18+
studentSet.forEach((value) => {
19+
result += value
20+
})
21+
console.log(result)
22+
23+
/**
24+
* Set集合中没有Key的概念
25+
* keys()方法和values()方法效果一样
26+
*/
27+
studentSet.values()

docs/.vuepress/config/sidebar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {ExpressSidebar} from "../../manuscripts/server-end/framework/express/exp
1818
import {DesignPatternsSidebar} from "../../manuscripts/server-end/design-patterns/designPatterns.sidebar";
1919
import {SequelizeOrmSidebar} from "../../manuscripts/server-end/orm/sequelize/sequelizeOrm.sidebar";
2020
import {TypeormSidebar} from "../../manuscripts/server-end/orm/typeorm/typeorm.sidebar";
21+
import {TypescriptSidebar} from "../../manuscripts/server-end/typescript/typescript.sidebar";
2122

2223
export default {
2324
"/manuscripts/front-end": FrontEndSidebar,
@@ -30,6 +31,7 @@ export default {
3031
"/manuscripts/server-end/database/mongo": MongoSideBar,
3132
"/manuscripts/server-end/linux": LinuxSidebar,
3233
"/manuscripts/server-end/design-patterns": DesignPatternsSidebar,
34+
"/manuscripts/server-end/typescript": TypescriptSidebar,
3335
"/manuscripts/server-end/base": BaseSidebar,
3436
"/manuscripts/server-end/node-learn": NodeLearnSidebar,
3537
"/manuscripts/server-end/orm/sequelize": SequelizeOrmSidebar,

docs/manuscripts/battle-interview/problems/Node面试.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ let arr2 = [...new Set(arr)]
305305

306306
- `typeof`:可以判断出`string`,`number`,`boolean`,`undefined`,`symbol`
307307
但判断 typeof(null) 时值为 `object`; 判断数组和对象时值均为 `object`
308-
- `instanceof`:原理是 构造函数的 prototype 属性是否出现在对象的原型链中的任何位置
308+
- `instanceof`:原理是 构造函数的 `prototype` 属性是否出现在对象的原型链中的任何位置
309309
- `Object.prototype.toString.call()`:常用于判断浏览器内置对象,对于所有基本的数据类型都能进行判断
310310
- `Array.isArray()`:只能用于判断是否为数组
311311
- `constructor`构造函数

0 commit comments

Comments
 (0)