(this: unknown, fn: T)
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | export function once<T extends Function>(this: unknown, fn: T): T { |
| 5 | const _this = this; |
| 6 | let didCall = false; |
| 7 | let result: unknown; |
| 8 | |
| 9 | return function () { |
| 10 | if (didCall) { |
| 11 | return result; |
| 12 | } |
| 13 | |
| 14 | didCall = true; |
| 15 | result = fn.apply(_this, arguments); |
| 16 | |
| 17 | return result; |
| 18 | } as unknown as T; |
| 19 | } |
no outgoing calls
no test coverage detected