Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Jan 27, 2024
1 parent 3c4d4ac commit 8eb205e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions content/prototype.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,32 @@ d.reduce((sum, currentValue) => sum + currentValue, initialValue)

> async/await 可以不用手写 promise, 让代码更加直观. 就是简化 Promise 写法
```js
function async1() {
return new Promise((resolve, reject) => {
setTimeout(() => {
// console.log('async');
return resolve('ok');
}, 1000);
});
}

async function main() {
const res = await async1();
console.log(res); // micro task
console.log('01');
}

function m1() {
return async1()
.then((res) => console.log(res)) // micro task
.then(() => console.log('01'));
}

main();
m1();
```


```js
const pro = new Promise((resolve, reject) => {
Expand All @@ -138,6 +164,8 @@ function f() {
f();
```

---

```js
// 第一个参数是指定原型对象
const d = Object.create({ age: 9 });
Expand Down

0 comments on commit 8eb205e

Please sign in to comment.