00001 var toInteger = require('./toInteger'); 00002 00004 var FUNC_ERROR_TEXT = 'Expected a function'; 00005 00023 function before(n, func) { 00024 var result; 00025 if (typeof func != 'function') { 00026 throw new TypeError(FUNC_ERROR_TEXT); 00027 } 00028 n = toInteger(n); 00029 return function() { 00030 if (--n > 0) { 00031 result = func.apply(this, arguments); 00032 } 00033 if (n <= 1) { 00034 func = undefined; 00035 } 00036 return result; 00037 }; 00038 } 00039 00040 module.exports = before;