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,360
  • 11
  • 46
  • 77
user994165
  • 8,710
  • 27
  • 89
  • 154

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,105
  • 4
  • 21
  • 24