Created
December 29, 2018 16:46
-
-
Save Caldis/d137cbd09c698ab7794ffce196599f58 to your computer and use it in GitHub Desktop.
使用点符号来设置/获取 Map 对象的值
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
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