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