Skip to content

Commit

Permalink
[feat] 更新 record
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlxq committed Sep 2, 2024
1 parent 6491820 commit ff881a0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/blog/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"name": "index",
"label": "原创笔记"
},
{
"type": "dir",
"name": "list",
"label": "一点记录"
},
{
"type": "file",
"name": "taro_3",
Expand Down
56 changes: 56 additions & 0 deletions docs/blog/list/magicai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

# 0902面试总结

## 手写题

1. usePrevious

```typescript
import { useEffect, useRef } from 'react';

export default function usePrevious<T>(state: T): T | undefined {
const ref = useRef<T>();

useEffect(() => {
ref.current = state;
}, [state]);

return ref.current;
}
```

2. LazyMan 类实现

```javascript

class LazyMan {
constructor(name) {
this.name = name;
console.log(name);

this.base = Promise.resolve()
}

sleep (time) {
this.base = this.base.then(() => {
return new Promise((resolve) => {
console.log(`等待${time}`)
setTimeout(() => {
resolve()
}, time * 1000);
})
})
return this;
}

eat (food) {
this.base = this.base.then(() => {
console.log(`正在吃${food}`)
})
return this;
}
}

new LazyMan('张三').eat('banana').sleep(3).eat('launch').sleep(4).eat('food');

```

0 comments on commit ff881a0

Please sign in to comment.