Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access private function in Node Module

I have a function exposed through export in a node module I'm building. I'd like to be able to have that function call an internal (private) function within the same module.

So far I have something like:

someModule.js

var publicFunc = function(a, b) {
  var obj = {result: 'of some processing'};
  return privateFunc(obj);
}

var privateFunc = function(obj) {
  /* proccessing */
  return result;
}

exports.publicFunc = publicFunc;

When publicFunc calls privateFunc I get:

Reference error: privateFunc is not defined;

like image 722
binarygiant Avatar asked Mar 06 '26 15:03

binarygiant


1 Answers

Change your declarations to function name(... instead of var name = function(...

function publicFunc(a, b) {
  var obj = {result: 'of some processing'};
  return privateFunc(obj);
}

function privateFunc (obj) {
  /* proccessing */
  return result;
}

exports.publicFunc = publicFunc;
like image 53
Ian Avatar answered Mar 08 '26 05:03

Ian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!