In this case add
method loses its internal this
context when you pass it as a callback, so you need to use bind
:
['bar', 'baz'].forEach(mySet.add.bind(mySet));
or
['bar', 'baz'].forEach((item) => mySet.add(item));
In this case add
method loses its internal this
context when you pass it as a callback, so you need to use bind
:
['bar', 'baz'].forEach(mySet.add.bind(mySet));
or
['bar', 'baz'].forEach((item) => mySet.add(item));