Created
July 9, 2018 12:05
-
-
Save nairihar/09aa969c61eceea09d60b8e1db039d97 to your computer and use it in GitHub Desktop.
JavaScript series, part 3, WeakMap and WeakSet, medium
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 weakMap = new WeakMap(); | |
const obj = {}; | |
weakMap.set(obj, 11); | |
weakMap.set(1,1); | |
// Uncaught TypeError: Invalid value used as weak map key | |
weakMap.get(obj); | |
// 11 | |
weakMap.get(5); | |
// undefined | |
weakMap.has(obj); | |
// true | |
weakMap.has(5); | |
// false | |
weakMap.delete(obj); | |
// true | |
weakMap.delete(5); | |
// false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment