Skip to content

Commit e5ae428

Browse files
committed
feat: update
1 parent 3d3b9fd commit e5ae428

File tree

4 files changed

+96
-8
lines changed

4 files changed

+96
-8
lines changed

1.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function sum(...args) {
2+
const arr = [...args];
3+
function add(...rest) {
4+
arr.push(...rest);
5+
return add;
6+
}
7+
add.toString = () => arr.reduce((pre, cur) => pre + cur, 0);
8+
return add;
9+
}
10+
11+
console.log("sum:" + sum(2)(3));
12+
console.log("sum:" + sum(2, 3)(3)(4));

2.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const urls = [
2+
{
3+
info: "link1",
4+
time: 2000,
5+
},
6+
{
7+
info: "link2",
8+
time: 3000,
9+
},
10+
{
11+
info: "link3",
12+
time: 3000,
13+
},
14+
{
15+
info: "link4",
16+
time: 5000,
17+
},
18+
];
19+
20+
function loadImg(url) {
21+
return new Promise((resolve, reject) => {
22+
console.log("--", url.info + "start");
23+
setTimeout(() => {
24+
console.log("--", url.info + "end");
25+
resolve();
26+
}, url.time);
27+
});
28+
}
29+
30+
class Scheduler {
31+
constructor(n) {
32+
this.max = n || 2;
33+
this.currentCount = 0;
34+
this.taskQueue = []; // 当前执行任务队列
35+
}
36+
37+
add(task) {
38+
this.taskQueue.push(task);
39+
this.run();
40+
}
41+
42+
run() {
43+
if (this.taskQueue.length === 0 || this.currentCount >= this.max) {
44+
return;
45+
}
46+
47+
this.currentCount++;
48+
const fn = this.taskQueue.shift();
49+
50+
fn()
51+
.then(() => {
52+
this._next();
53+
})
54+
.catch(() => {
55+
this._next();
56+
});
57+
}
58+
59+
_next() {
60+
this.currentCount--;
61+
this.run();
62+
}
63+
}
64+
65+
const scheduler = new Scheduler();
66+
67+
urls.forEach((url) => {
68+
scheduler.add(() => loadImg(url));
69+
});

docs/interview/13-react.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- 16.8:hooks
77
- 17:过渡版本
88
- 18:concurrent mode
9+
- 19:编译(自动 memo 化), RSC的更新
910

1011
## setState 是同步还是异步
1112

docs/interview/4-browser.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,25 @@ Node:
3737

3838
## 3.浏览器存储
3939

40-
**Cookie**:4K,用于 HTTP 请求头,同源,每个域名 Cookie 数量不超过 20 个
40+
**Cookie**
41+
42+
主要用于,会话状态管理,用户跟踪。
43+
缺点:空间小 4K 限制;网络请求会携带影响性能;安全和隐私问题,如 CSRF
4144

42-
- 可设置有效期(`Expires`/`Max-Age`
4345
- `Domain`/`Path` 定义了 Cookie 的作用域
46+
- 可设置有效期(`Expires`/`Max-Age`
47+
- `HttpOnly` 限制 JS 访问(`document.cookie`),减少 XSS 风险
4448
- `Secure` 标记为只能通过 HTTPS 发送
45-
- `HttpOnly` 无法通过 JS 访问( Document.cookie)
46-
- `SameSite` 限制 Cookie 在跨站请求时不会被发送,同站:**二级域名**
47-
- 主要用于,会话状态管理,行为跟踪。
48-
- 缺点:空间小,网络请求会携带
4949

50-
> https://juejin.cn/post/6963632513914765320
50+
第三方 Cookie 的问题:
5151

52-
> https://juejin.cn/post/7171349320904474632
52+
- `SameSite` 限制三方 Cookie 在跨站(顶级域名不同)请求时不会被发送,http 不支持,需要同时设置`Secure`
53+
- `Strict` 不允许跨站
54+
- `Lax` 允许部分请求,如 `a``link`
55+
- `None` 不限制
56+
- Chrome 80+ 默认是 `Lax`
57+
- Chrome 新版本浏览器停用第三方 Cookie
58+
- Chrome 114 增加了 Cookie 独立分区 新属性,`Partitioned`, 第三方 cookie 可以用。 跨站不共享
5359

5460
> 操作:document.cookie 读取/或写入,写入是追加
5561

0 commit comments

Comments
 (0)