Last active
August 29, 2015 14:12
-
-
Save dherman/fbf3077a2781df74b6d8 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
import * as fs from "fs"; | |
let exports; | |
// reflective API takes environment descriptors and uses revealing constructor pattern | |
// to expose mutators to the creator of the module instance object | |
var mod = new Reflect.Module({ | |
// initialized mutable (includes "uninitialized" var) | |
x: { value: undefined }, | |
y: { value: 42 }, | |
// uninitialized mutable (let, class) | |
z: { }, | |
// initialized immutable (const) | |
PI: { value: Math.PI, const: true }, | |
// uninitialized immutable (const) | |
TAU: { const: true }, | |
// re-export | |
readFile: { module: fs, import: "readFile" } | |
}, function(mutator) { exports = mutator; }); | |
// mutator object uses setters to write through to the module's encapsulated environment | |
console.log(mod.y); // 42 | |
exports.y = 43; | |
console.log(mod.y); // 43 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment