-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeta-Programming.js
More file actions
28 lines (25 loc) · 928 Bytes
/
Copy pathMeta-Programming.js
File metadata and controls
28 lines (25 loc) · 928 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
"use strict";
//------------------------------------------------------------------------------
// Proxying
// Hooking into runtime-level object meta-operations.
// http://es6-features.org/#Proxying
//------------------------------------------------------------------------------
let target = {
foo: "Welcome, foo"
}
let proxy = new Proxy(target, {
get (receiver, name) {
return name in receiver ? receiver[name] : `Hello, ${name}`
}
})
proxy.foo === "Welcome, foo"
proxy.world === "Hello, world"
//------------------------------------------------------------------------------
// Reflection
// Make calls corresponding to the object meta-operations.
// http://es6-features.org/#Reflection
//------------------------------------------------------------------------------
let obj = { a: 1 }
Object.defineProperty(obj, "b", { value: 2 })
obj[Symbol("c")] = 3
Reflect.ownKeys(obj) // [ "a", "b", Symbol(c) ]