Updated to use @skatcat31's suggestion

This commit is contained in:
Angelos Chalaris
2018-01-02 10:48:08 +02:00
committed by GitHub
parent 947a8b315a
commit bc5bea609f

View File

@ -6,15 +6,7 @@ Utilizing a closure, use a flag, `called`, and set it to `true` once the functio
Allow the function to be supplied with an arbitrary number of arguments using the spread (`...`) operator.
```js
const once = fn => {
let called = false;
return (...args) => {
if (!called) {
fn(...args);
called = true;
}
};
};
const once = fn => (called => (...args) => !called ? (called = true, fn(...args)) : undefined)()
```
```js