global-cache
Sometimes you have to do horrible things, like use the global object to share a singleton. Abstract that away, with this!
This attaches a cache to the global object. It attempts to make it as undiscoverable as possible:
- uses Symbols if available
- if not, uses a string key that is not a valid identifier, so as not to show up in dot-notation browser autocomplete
- makes it non-enumerable if property descriptors are supported
Keys are required to be strings or symbols.
Example
var cache = ;var assert = ; var value = {};;; cache;;; cache;;;
Tests
Simply clone the repo, npm install
, and run npm test