Skip to content

Instantly share code, notes, and snippets.

@fuchao2012
Created February 23, 2017 09:10
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 fuchao2012/51a56ba7c6fdfd2d2c38f2a5036604b7 to your computer and use it in GitHub Desktop.
Save fuchao2012/51a56ba7c6fdfd2d2c38f2a5036604b7 to your computer and use it in GitHub Desktop.
Symbol
// 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