Set.prototype.toggle

Cyril Auburtin cyril.auburtin at gmail.com
Sat Oct 28 19:56:49 UTC 2017


extending Set is possible

```js
class SetWithToggle extends Set {
toggle(value, force = !this.has(value)) {
if (force) {
this.add(value);
} else {
this.delete(value);
}
return this;
}
};
```

2017-10-28 17:15 GMT+02:00 Cyril Auburtin <cyril.auburtin at gmail.com>:

> It would help to avoid this scenario:
> ```js
> if (cond) {
>   set.add(x);
> } else {
>   set.delete(x);
> }
> // set.toggle(x, cond);
> ```
>
> It's similar to Element's classList
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171028/487ef7e1/attachment.html>


More information about the es-discuss mailing list