Created
September 16, 2016 13:10
-
-
Save RSO/730f03310422454ad144f525d8c7584b to your computer and use it in GitHub Desktop.
This file contains 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
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