forked from shama/letswritecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (36 loc) · 941 Bytes
/
index.js
File metadata and controls
53 lines (36 loc) · 941 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
42
let bears = { grizzly: true }
let grizzlyCount = 0
const proxyBears = new Proxy(bears, {
get: function (target, prop) {
if (prop === 'grizzly') grizzlyCount++
return target[prop]
},
set: function (target, prop, value) {
if (['grizzly', 'brown', 'polar'].indexOf(prop) === -1) {
throw new Error('THAT IS TOTALLY NOT A BEAR!')
}
target[prop] = value
},
deleteProperty: function (target, prop) {
console.log(`You have deleted ${prop}`)
delete target[prop]
}
})
//proxyBears.aardvark = true
proxyBears.polar = true
//delete proxyBears.polar
//console.log(proxyBears.polar)
// proxyBears.grizzly
// proxyBears.grizzly
// proxyBears.grizzly
// proxyBears.grizzly
// console.log(grizzlyCount)
function growl() {
return 'grrr'
}
const loudGrowl = new Proxy(growl, {
apply: function (target, thisArg, args) {
return target().toUpperCase() + '!!!'
}
})
console.log(loudGrowl())