File tree 4 files changed +96
-8
lines changed
4 files changed +96
-8
lines changed Original file line number Diff line number Diff line change
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 ) ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change 6
6
- 16.8:hooks
7
7
- 17:过渡版本
8
8
- 18:concurrent mode
9
+ - 19:编译(自动 memo 化), RSC的更新
9
10
10
11
## setState 是同步还是异步
11
12
Original file line number Diff line number Diff line change @@ -37,19 +37,25 @@ Node:
37
37
38
38
## 3.浏览器存储
39
39
40
- ** Cookie** :4K,用于 HTTP 请求头,同源,每个域名 Cookie 数量不超过 20 个
40
+ ** Cookie** :
41
+
42
+ 主要用于,会话状态管理,用户跟踪。
43
+ 缺点:空间小 4K 限制;网络请求会携带影响性能;安全和隐私问题,如 CSRF
41
44
42
- - 可设置有效期(` Expires ` /` Max-Age ` )
43
45
- ` Domain ` /` Path ` 定义了 Cookie 的作用域
46
+ - 可设置有效期(` Expires ` /` Max-Age ` )
47
+ - ` HttpOnly ` 限制 JS 访问(` document.cookie ` ),减少 XSS 风险
44
48
- ` Secure ` 标记为只能通过 HTTPS 发送
45
- - ` HttpOnly ` 无法通过 JS 访问( Document.cookie)
46
- - ` SameSite ` 限制 Cookie 在跨站请求时不会被发送,同站:** 二级域名**
47
- - 主要用于,会话状态管理,行为跟踪。
48
- - 缺点:空间小,网络请求会携带
49
49
50
- > https://juejin.cn/post/6963632513914765320
50
+ 第三方 Cookie 的问题:
51
51
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 可以用。 跨站不共享
53
59
54
60
> 操作:document.cookie 读取/或写入,写入是追加
55
61
You can’t perform that action at this time.
0 commit comments