Skip to content

Instantly share code, notes, and snippets.

@RSO
Created September 16, 2016 13:10
Show Gist options
  • Save RSO/730f03310422454ad144f525d8c7584b to your computer and use it in GitHub Desktop.
Save RSO/730f03310422454ad144f525d8c7584b to your computer and use it in GitHub Desktop.
const lazy = function(name, func) {
let cached = null;
afterEach(function() {
delete global[`$${name}`];
cached = undefined;
});
Object.defineProperty(global, `$${name}`, {
configurable: true,
get() {
if (cached) {
return cached;
}
cached = func();
return cached;
},
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment