-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproxy.html
More file actions
41 lines (36 loc) · 947 Bytes
/
proxy.html
File metadata and controls
41 lines (36 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Proxy</title>
</head>
<body>
<script>
const target = {
middleName: "Kurniawan"
};
const handler = {
get: function (target, property) {
console.info(`Access property : ${property}`);
return target[property];
},
set: function (target, property, value) {
console.info(`Change property ${property} : ${value}`)
if(value == null){
// throw new Error("Tidak boleh null");
target[property] = "";
}else{
target[property] = value;
}
}
};
const proxy = new Proxy(target, handler);
proxy.firstName = "Eko";
proxy.lastName = null;
console.info(proxy.firstName);
console.info(proxy.middleName);
console.info(proxy.lastName);
console.info(target);
</script>
</body>
</html>