Skip to content

Instantly share code, notes, and snippets.

@dherman
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dherman/fbf3077a2781df74b6d8 to your computer and use it in GitHub Desktop.
Save dherman/fbf3077a2781df74b6d8 to your computer and use it in GitHub Desktop.
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