Skip to content

Instantly share code, notes, and snippets.

@Caldis
Created December 29, 2018 16:46
Show Gist options
  • Save Caldis/d137cbd09c698ab7794ffce196599f58 to your computer and use it in GitHub Desktop.
Save Caldis/d137cbd09c698ab7794ffce196599f58 to your computer and use it in GitHub Desktop.
使用点符号来设置/获取 Map 对象的值
const sourceMap = new Map()
const enhanceMap = new Proxy(sourceMap, {
get: (obj, prop) =>
obj.get(prop),
set: (obj, prop, value) => {
obj.set(prop, value)
return true
}
})
enhanceMap.testString = 'Yay'
console.log(enhanceMap.testString, sourceMap.get('testString'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment