Last active
August 29, 2015 14:11
-
-
Save tyage/52c1f3ee159512a9a7f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ref: https://github.com/toshok/echo-js/blob/e9d3c55cd9eb852c627d1bd0f28972b99a137a40/runtime/ejs-reflect.c | |
| let foo = { | |
| bar: 123 | |
| }; | |
| let sym = Symbol('test') | |
| foo[sym] = 456 | |
| // Reflect.get | |
| console.log(Reflect.get(foo, 'bar')) // => 123 | |
| console.log(Reflect.get(foo, sym)) // => 456 | |
| // Reflect.set | |
| Reflect.set(foo, 'var', 789) | |
| console.log(Reflect.get(foo, 'var')) // => 789 | |
| // Reflect.has | |
| console.log(Reflect.has(foo, 'bar')) // => true | |
| /* | |
| // not implemented in echo-js | |
| // Reflect.deleteProperty | |
| Reflect.deleteProperty(foo, 'var') | |
| console.log('var' in foo) // => undefined | |
| */ | |
| // Reflect.getOwnPropertyDescriptor | |
| let desc = Reflect.getOwnPropertyDescriptor(foo, 'bar') | |
| console.log(desc.value) // => 123 | |
| /* | |
| // not implemented in echo-js | |
| // Reflect.defineProperty | |
| Reflect.defineProperty(foo, 'var', { value: 345, writable: false }) | |
| console.log(foo.var) | |
| */ | |
| // Reflect.getPrototypeOf, Reflect.setPrototypeOf | |
| let obj = {} | |
| Reflect.setPrototypeOf(obj, Array.prototype) | |
| console.log(Reflect.getPrototypeOf(obj) === Array.prototype) // => true | |
| // Reflect.isExtensible, Reflect.preventExtensions | |
| Reflect.preventExtensions(obj) | |
| console.log(Reflect.isExtensible(obj)) // => false | |
| /* | |
| // not implemented in echo-js | |
| // Reflect.enumerate | |
| for (let item in Reflect.enumerate(foo)) { | |
| console.log(foo) | |
| } | |
| */ | |
| // Reflect.ownKeys | |
| // why symbol key returns as 0 in echo-js? | |
| console.log(Reflect.ownKeys(foo)) // => [ bar, var, 0 ] | |
| // Reflect.apply | |
| let arr = [1, 2] | |
| Reflect.apply(Array.prototype.push, arr, [3, 4, 5]) | |
| console.log(arr) // => [ 1, 2, 3, 4, 5 ] | |
| /* | |
| // not implemented in echo-js | |
| // Reflect.construct | |
| class C { | |
| constructor() { | |
| this.x = 1 | |
| } | |
| } | |
| console.log(Reflect.construct(C).x) // => 1 | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment