0

I'm trying to get access to this in a function, but it's undefined.

function processEachPath(element, index, list) {
    logger.debug(this);

}

...

_.each(config, processEachPath);
blackpanther
  • 10,998
  • 11
  • 48
  • 78
user994165
  • 9,146
  • 30
  • 98
  • 165

1 Answers1

1

You need to explicitly bind it to the function:

function processEachPath(element, index, list) {
    logger.debug(_this);
}

// ...

(processEachPath.bind(this))();
Darkhogg
  • 13,707
  • 4
  • 22
  • 24