File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! The Proxy object enables you to create a proxy for another object, which can intercept and redefine fundamental operations for that object.
2
+
3
+ const john = { status : "looking for work" } ;
4
+
5
+ const handler = {
6
+ get : function ( target , propName ) {
7
+ console . log ( target ) ;
8
+ console . log ( propName ) ;
9
+ return target [ propName ] ;
10
+ } ,
11
+ } ;
12
+
13
+ // const agent = new Proxy(john, {});
14
+ // console.log(agent.status);
15
+
16
+ const agent = new Proxy ( john , handler ) ;
17
+ console . log ( agent . status ) ;
18
+
19
+ console . log ( "---------------------" ) ;
20
+
21
+ const ohi = { job : "student " } ;
22
+ const handler2 = {
23
+ set ( target , propName , value ) {
24
+ if ( propName === "payRate" ) {
25
+ value = value * 0.85 ;
26
+ }
27
+ target [ propName ] = value ;
28
+ } ,
29
+ } ;
30
+ const agent2 = new Proxy ( ohi , handler2 ) ;
31
+ agent2 . payRate = 1000 ;
32
+ console . log ( agent2 . payRate ) ;
You can’t perform that action at this time.
0 commit comments