|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
445 bytes
|
| Line | |
|---|
| 1 | import { toInteger } from '../util/toInteger.mjs';
|
|---|
| 2 |
|
|---|
| 3 | function before(n, func) {
|
|---|
| 4 | if (typeof func !== 'function') {
|
|---|
| 5 | throw new TypeError('Expected a function');
|
|---|
| 6 | }
|
|---|
| 7 | let result;
|
|---|
| 8 | n = toInteger(n);
|
|---|
| 9 | return function (...args) {
|
|---|
| 10 | if (--n > 0) {
|
|---|
| 11 | result = func.apply(this, args);
|
|---|
| 12 | }
|
|---|
| 13 | if (n <= 1 && func) {
|
|---|
| 14 | func = undefined;
|
|---|
| 15 | }
|
|---|
| 16 | return result;
|
|---|
| 17 | };
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | export { before };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.