Created
February 23, 2017 09:10
-
-
Save fuchao2012/51a56ba7c6fdfd2d2c38f2a5036604b7 to your computer and use it in GitHub Desktop.
Symbol
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
// demo | |
let privateDataStore = { | |
set(val){ | |
let key = Symbol(Math.random().toString(32).substr(2)) | |
this[key]=val | |
return key | |
} | |
get(key){ | |
return this[key] | |
} | |
} | |
//use | |
let key = privateDataStore('hello') | |
privateDataStore[key] | |
privateDataStore.get(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment