File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -10,14 +10,26 @@ let target = {
10
10
} ;
11
11
12
12
let proxy = new Proxy ( target , {
13
- get ( receiver , name ) {
14
- return name in receiver ? receiver [ name ] : `Howdy, ${ name } `
13
+ get ( obj , prop , val ) {
14
+ return val in obj ? obj [ val ] : 'Howdy, ${val}'
15
+ } ,
16
+ set ( obj , prop , val ) {
17
+ if ( prop === 'password' ) {
18
+ if ( prop . length < 8 ) {
19
+ throw new TypeError ( 'The length of password should be greater than 8' ) ;
20
+ } else {
21
+ obj [ prop ] = val ;
22
+ }
23
+ } else {
24
+ obj [ prop ] = val ;
25
+ }
15
26
}
16
27
} ) ;
17
28
18
29
proxy . guest ; // "Welcome, Guest"
19
- proxy . userX // "Howdy, UserX"
20
-
30
+ proxy . userX ; // "Howdy, UserX"
31
+ proxy . password = 'abc' ; //Error The length of password should be greater than 8.
32
+ proxy . age = 22 ; //age=22
21
33
22
34
23
35
You can’t perform that action at this time.
0 commit comments