Skip to content

Instantly share code, notes, and snippets.

@jovey-zheng
Created April 5, 2017 09:20
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 jovey-zheng/1b93e9bd4e5298da574d3d809a69614b to your computer and use it in GitHub Desktop.
Save jovey-zheng/1b93e9bd4e5298da574d3d809a69614b to your computer and use it in GitHub Desktop.
// 简单的缓存工具
// 匿名函数创造了一个闭包
const cache = (function() {
const store = {};
return {
get(key) {
return store[key];
},
set(key, val) {
store[key] = val;
}
}
}());
cache.set('a', 1);
cache.get('a'); // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment