Skip to content

Instantly share code, notes, and snippets.

@cesarkohl
Created January 13, 2020 14:39
Show Gist options
  • Select an option

  • Save cesarkohl/e3ee0cb764757b6cc919fd213374a3b2 to your computer and use it in GitHub Desktop.

Select an option

Save cesarkohl/e3ee0cb764757b6cc919fd213374a3b2 to your computer and use it in GitHub Desktop.
var weakMap = new WeakMap ();
var element1 = window;
var element2 = document.querySelector ('body');
weakMap.set (element1, 'I am element1');
weakMap.set (element2, 'I am element2');
At this time, when we retrieve the values ​​through the keys, we will get the expected result:
console.log (weakMap.get (element1));
console.log (weakMap.get (element2));
// output
// I am element1
// I am element2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment