Skip to content

Commit 5e2677d

Browse files
author
YuChengKai
committed
2 parents 265e55f + 0a3e570 commit 5e2677d

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

Framework/framework-zh.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# VDOM
2+
3+
4+
5+
- 节点不一样就直接干掉
6+
- 相同的节点,先对比属性
7+
- 对于子节点,需要用 key 告诉我怎么复用,否则就按照上面的方式判断
8+

JS/JS-ch.md

+22
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,28 @@ test()
13611361
13621362
`asyncawait` 相比直接使用 `Promise` 来说,优势在于处理 `then` 的调用链,能够更清晰准确的写出代码。缺点在于滥用 `await` 可能会导致性能问题,因为 `await` 会阻塞代码,也许之后的异步代码并不依赖于前者,但仍然需要等待前者完成,导致代码失去了并发性。
13631363
1364+
下面来看一个使用 `await` 的代码。
1365+
1366+
```js
1367+
var a = 0
1368+
var b = async () => {
1369+
a = a + await 10
1370+
console.log('2', a) // -> '2' 10
1371+
a = (await 10) + a
1372+
console.log('3', a) // -> '3' 20
1373+
}
1374+
b()
1375+
a++
1376+
console.log('1', a) // -> '1' 1
1377+
```
1378+
1379+
对于以上代码你可能会有疑惑,这里说明下原理
1380+
1381+
- 首先函数 `b` 先执行,在执行到 `await 10` 之前变量 `a` 还是 0,因为在 `await` 内部实现了 `generators``generators` 会保留堆栈中东西,所以这时候 `a = 0` 被保存了下来
1382+
- 因为 `await` 是异步操作,所以会先执行 `console.log('1', a)`
1383+
- 这时候同步代码执行完毕,开始执行异步代码,将保存下来的值拿出来使用,这时候 `a = 10`
1384+
- 然后后面就是常规执行代码了
1385+
13641386
# Proxy
13651387
13661388
Proxy 是 ES6 中新增的功能,可以用来自定义对象中的操作

JS/JS-en.md

+22
Original file line numberDiff line numberDiff line change
@@ -973,3 +973,25 @@ test()
973973
The above code will print `finish` before printing `object`. Because `await` waits for the `sleep` function `resolve`, even if the synchronization code is followed, synchronization code is not executed before the asynchronization code is executed.
974974
975975
The advantage of `async` and `await` compared to the direct use of `Promise` lies in handling the call chain of `then`, which can write code more clearly and accurately. The downside is that misuse of `await` can cause performance problems because `await` blocks the code. Perhaps the asynchronous code does not depend on the former, but it still needs to wait for the former to complete, causing the code to lose concurrency.
976+
977+
Let's look at a code that uses `await`.
978+
979+
```js
980+
var a = 0
981+
var b = async () => {
982+
a = a + await 10
983+
console.log('2', a) // -> '2' 10
984+
a = (await 10) + a
985+
console.log('3', a) // -> '3' 20
986+
}
987+
b()
988+
a++
989+
console.log('1', a) // -> '1' 1
990+
```
991+
992+
You may have doubts about the above code, here explain the principle
993+
994+
- First the function `b` is executed. The variable `a` is still 0 before execution `await 10`, Because the `generators` are implemented inside `await` and `Generators` will keep things in the stack, so at this time `a = 0` is saved
995+
- Because `await` is an asynchronous operation, `console.log('1', a)` will be executed first.
996+
- At this point, the synchronization code is executed and asynchronous code is started. The saved value is used. At this time, `a = 10`
997+
- Then comes the usual code execution

0 commit comments

Comments
 (0)