12345678910111213141516171819202122232425262728293031323334353637383940 |
- var toInteger = require('./toInteger');
- var FUNC_ERROR_TEXT = 'Expected a function';
- function before(n, func) {
- var result;
- if (typeof func != 'function') {
- throw new TypeError(FUNC_ERROR_TEXT);
- }
- n = toInteger(n);
- return function() {
- if (--n > 0) {
- result = func.apply(this, arguments);
- }
- if (n <= 1) {
- func = undefined;
- }
- return result;
- };
- }
- module.exports = before;
|