Created
April 5, 2017 09:20
-
-
Save jovey-zheng/1b93e9bd4e5298da574d3d809a69614b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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