Skip to content

Instantly share code, notes, and snippets.

@danfinlay
Created November 21, 2019 19:40
Show Gist options
  • Save danfinlay/cbda4c2b03fb4de73627bd319b80d089 to your computer and use it in GitHub Desktop.
Save danfinlay/cbda4c2b03fb4de73627bd319b80d089 to your computer and use it in GitHub Desktop.
Proof that JavaScript maps index functions by identity, not source string.
const funcString = '() => "foo"';
const funcA = new Function(funcString);
const funcB = new Function(funcString);
const map = new Map();
map.set(funcA, 'a');
map.set(funcB, 'b');
const aVal = map.get(funcA);
console.log(aVal === 'a');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment