Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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