Skip to content

Commit 2c6cb4f

Browse files
committed
echmaScript proxy
1 parent 101fe49 commit 2c6cb4f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

_data/toc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ es6:
193193
title: set
194194
- path: /javascript-developer/es/weakset/
195195
title: weakset
196+
- path: /javascript-developer/es/proxy/
197+
title: proxy
196198
- path: /javascript-developer/es/class/
197199
title: class
198200
- path: /javascript-developer/es/getter-setter/

javascript-developer/es/proxy.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
description: echmaScript proxy
3+
keywords: es,es6,js,es6_proxy
4+
title: echmaScript proxy
5+
toc_max: 4
6+
---
7+
8+
What is proxy?
9+
10+
In JavaScript, a proxy is an object that controls access to another object, called the target object. You can use a proxy to intercept and modify the behavior of operations performed on the target object, such as getting and setting properties, calling methods, and creating new objects.
11+
12+
~ courtesy chatgpt
13+
14+
15+
# example
16+
17+
```js
18+
let user = {name: 'kamal', age: 21}
19+
20+
let handler = {
21+
get(target, name){
22+
return target[name].toUpperCase()
23+
},
24+
set(target, name, value) {
25+
if(typeof value === 'string') {
26+
target[name] = value.trim().toUpperCase();
27+
}
28+
}
29+
}
30+
31+
let userProxy = new Proxy(user,handler)
32+
33+
userProxy.name = 'mostafa'
34+
35+
console.log(userProxy.name)
36+
```
37+
38+
# Resources
39+
* [proxy - Nodecasts youtube](https://www.youtube.com/watch?v=KJ3uYyUp-yo)

0 commit comments

Comments
 (0)