artdaq_node_server  v1_00_08
 All Classes Namespaces Files Variables Pages
before.js
1 var toInteger = require('./toInteger');
2 
4 var FUNC_ERROR_TEXT = 'Expected a function';
5 
23 function before(n, func) {
24  var result;
25  if (typeof func != 'function') {
26  throw new TypeError(FUNC_ERROR_TEXT);
27  }
28  n = toInteger(n);
29  return function() {
30  if (--n > 0) {
31  result = func.apply(this, arguments);
32  }
33  if (n <= 1) {
34  func = undefined;
35  }
36  return result;
37  };
38 }
39 
40 module.exports = before;