ES6 Map: Why/When to use an object or a function as a key?

Viewed 1932

I've read what a Map is, and understand the differences between in Object vs Map. What I don't understand is why I would ever use objects or functions as the keys which a Map allows.

Question: Why & When would I ever set an object or a function as a key?

3 Answers

for test cases for example :

const test= new Map();

test.set('isZero', (v) => console.log(v === 0));
test.set('isNumber', (v) => console.log(typeof v === 'number'));

const value = 10;

for(let [key, fn] of test){
  // console.warn(key);
  fn(value);
}
Related